Jump to content


HELP!! - mysql database/php help

  • Please log in to reply
3 replies to this topic

#1 shmickvl

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 22 July 2006 - 07:56 AM

Hi guys

im having some trouble.
i create a table in phpmyadmin, with two fields for example: id and name. i set my id field to auto increment, not null, and the primary key. i have made a "index.html" form to submit data, and made my "submission.php" page which takes it all there. The problem is that in my table, if i have the id field, data will not go to the database. However, if i delete the id field, it will go there.

PLease help

attached are my codes.

<form action="submission.php" method="post">
First Name: <input type="text" name="name"><br>
<input type="Submit">

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("example") or die(mysql_error());
mysql_query("INSERT INTO `example1` VALUES ('$name')");
Print "Your information has been successfully added to the database.";

cheers for your help

#2 king arthur

king arthur
  • Members
  • PipPipPip
  • Advanced Member
  • 335 posts
  • LocationUK HQ

Posted 22 July 2006 - 10:26 AM

When you use this syntax
mysql_query("INSERT INTO `example1` VALUES ('$name')");

you must supply values for all the fields in the right order, even if one of them is auto-incremented, so if your id field is first in the table for example:

mysql_query("INSERT INTO `example1` VALUES (NULL, '$name')");

the NULL will be replaced by the auto-increment value.

Or you could use the syntax
mysql_query("INSERT INTO `example1` (name) VALUES ('$name')");

Sir Isaac Newton said "If I have seen farther, it is by standing on the shoulders of giants". But it is not recorded as to whether he said it before or after he was hit on the head by a falling apple.

#3 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 22 July 2006 - 04:13 PM

As a rule, you should never rely on the column order, and always specify the column list for which you are providing values.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#4 shmickvl

  • New Members
  • Pip
  • Newbie
  • 2 posts

Posted 23 July 2006 - 06:33 AM


it worked!!!!!!! yay!!! its been bugging me for hours. im learning mysql/php :)

thanks again guys. so simple!!!

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users