> Dear friends,
> Form doesn't write to mysql database. I have pasted code of mysal
> table structure,html form and php script. Any comments, please.

> // create the SQL statement
> $sql = "INSERT INTO testtable values ('{'', $_POST['testField']}','
> {'', $_POST['testFielda']}','{'', $_POST['testFieldb']}','{'',
> $_POST['testFieldd']}','
> {'', $_POST['testFieldc']}','{'', $_POST['testFielde']}')";

I tried your code on my system and got an error of 'incorrect number of
parameters'.  That's when I realized you need NULL as the first
parameter in your values.  I didn't see in the MySQL docs where it
requires the NULL, but in one of the examples, it was there.

Insert NULL as the first parameter and it should work.

I also got a parse error because of the '{' and '}' symbols around your
$_POST variables.  I changed it to:

$sql = "INSERT INTO testtable values ( NULL, '".$_POST['testField']."',
'".$_POST['testFielda']."', '".$_POST['testFieldb']."',
'".$_POST['testFieldd']."', '".$_POST['testFieldc']."',
'".$_POST['testFielde']."' )";

and got a working solution.

Suggestion: You could try using the mysql_errno() and mysql_error()
functions.  Print them out after your failed statement and you'll see
why the mysql call failed.

  print "Error # ".mysql_errno()." - ".mysql_error()."<BR>\n";

will print the error number and message.  This will give you some idea
of what went wrong.

Good coding practice dictates that you check for an error condition
after mysql calls [using mysql_errno()] and handle any errors

If you don't already have it, you'll want a list of the error codes and
their meanings.  You can find it in the mysql source code
Docs/mysqld_error.txt file.  If you can't find that right now, copy this
web page I whipped up right now:


or, if you prefer a flat, text file:


Good luck!

:Mike S.
:Austin TX

Sent: February 7, 2004, 6:48 pm

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to