Forum Moderators: coopster

Message Too Old, No Replies

Form Processing: PHP --> MySQL

         

nir0

9:27 pm on Mar 30, 2004 (gmt 0)

10+ Year Member



HTML form posting to a php file which inputs to a myqsl database. Keep getting "Could not execute mysql query!"

Any ideas?

------------------------------------------
<?php

$connect= mysql_connect("localhost","root","****xx") or die("Could not connect to database in localhost!");

$result= mysql_select_db("outagedb") or die("Could not select outagedb database!");

$sqlquery= "insert INTO outagetb (name,date,device,tac,utt,description)

VALUES=
('$name',
'$date',
'$device',
'$tac',
'$utt',
'$description')";

$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query!");

echo "<table border=1 align=center width=500>";
echo " <tr> ";
echo " <td> ";
echo " Name";
echo " </td>";
echo " <td>".$name. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo " Date";
echo " </td>";
echo " <td >".$date. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo " Device";
echo " </td>";
echo " <td >".$device. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo " Tac Case";
echo " </td>";
echo " <td >".$tac. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo " UTT Ticket";
echo " </td>";
echo " <td >".$utt. "</td>";
echo " </tr>";
echo " <tr> ";
echo " <td > ";
echo " Description";
echo " </td>";
echo " <td>".$description. "</td>";
echo " </tr>";
echo "</table>";

?>

jatar_k

9:33 pm on Mar 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld nir0,

try getting the actual error from mysql like so

change this line

$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query!");

to

$queryresult = mysql_query($sqlquery) or die(mysql_error() [ca.php.net]);

that should help you get more detailed information about the actual error.

nir0

10:04 pm on Mar 30, 2004 (gmt 0)

10+ Year Member



Ok, gave it a try and now got:

You have an error in your SQL syntax near '(name,date,device,tac,utt,description) VALUES= ('', '', '', '', '', '')' at line 1

------------------------------------------

Here's a question which I'm not sure if it's the cause of my problem....

I have a field in the table called "key".....
Does this field need to be in the php script? Does it need to be in the form as a hidden field or something?

Sorry for the newbie questions....trying to learn.

jatar_k

10:17 pm on Mar 30, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>>Sorry for the newbie questions

no worries :)

>>trying to learn

that's what we're here for

As you can see it isn't getting the variables that are posted from the form.

VALUES= ('', '', '', '', '', '')

obviously they are all blank. Did you submit a blank form? if not you may want to do this

extract($_POST);
$sqlquery= "insert INTO outagetb (name,date,device,tac,utt,description) VALUES=('$name', '$date', '$device', '$tac', '$utt', '$description')";

is the key field PRIMARY KEY AUTO_INCREMENT?

nir0

11:58 pm on Mar 30, 2004 (gmt 0)

10+ Year Member



What does this do: extract($_POST);?

Yes, the field 'key' is set as primary auto-increment.

The form isn't blank...I'm not sure why the variables are not being picked up.

By the way, in case I forget...thanks for the time.

I set up the table with 7 fields...("key" being the one used as the primary). On my form, I only have the 6 form fields(name,date,device,tac,utt,description ) and pointed the action POST to the php script.

I'm not sure if I need to do anything with the "key" field other than put it in the table for indexing purposes. I didn't mention it anywhere on the html form or the php script.

The connection to the SQL seems to be ok. I'm actually pretty new at PHP...so there might be some basic step I'm missing.

nir0

12:32 am on Mar 31, 2004 (gmt 0)

10+ Year Member



Maybe I should start over. Not sure if this php script is on the right track.

All I'm looking to do is make a form with those 6 fields populate a mysql table. Is this script ok for this or should I do something different?

coopster

12:41 am on Mar 31, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



No, I think you are on the right track, but you have your syntax incorrect. Get the equal sign out of your SQL statement and you should get a little further...
$sqlquery= "insert INTO outagetb (name,date,device,tac,utt,description) 
VALUES
('$name',
'$date',
'$device',
'$tac',
'$utt',
'$description')";
You will still need to get your columns from the form data though as jatar_k suggested earlier.

nir0

3:42 pm on Mar 31, 2004 (gmt 0)

10+ Year Member



Thanks fellas. The [extract($_POST);] & [VALUE=] suggestions were the fix for my issues. I can post and the database is getting populated correctly.

Now on to my next task. Search and edit scripts.
Wish me luck. I'll probably be back.

;-)

jatar_k

8:01 pm on Mar 31, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



nice spot coopster, I totally missed the = , even reposted it without noticing.

We all need an extra pair of eyes. ;)

nir0

12:59 am on Apr 1, 2004 (gmt 0)

10+ Year Member



Damn.....I'm back quicker than I expected.
So I'm a bit lost. I've got a php script that processes the form posts into a database. I need a couple of options here...

1)I need to let the person posting know that the post was succesful.
2)I need to have an option of searching the database and displaying results from past posts

Any ideas or tutorials to get me started? I've been cruising other posts but it's only confusing me further. No 2 scripts are alike. I see some basic syntax (like connecting to a databse, or querying a databse)...but I'm not sure how or where to put this code.

I have 1 html page with the form and 1 php file that does the first processing. What now?

Maybe I should buy a book...but that means I would need to learn how to read ;)

coopster

3:59 pm on Apr 1, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>>We all need an extra pair of eyes.

More truth to that statement than you could imagine! That's why we come here.

nir0, have you trolled through the PHP Library [webmasterworld.com] here yet? There are a couple threads in there that should really help you get going...