shmickvl Posted July 22, 2006 Share Posted July 22, 2006 Hi guysim 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 helpattached are my codes.<html><body><form action="submission.php" method="post">First Name: <input type="text" name="name"><br><input type="Submit"></form></body></html><?$name=$_POST['name'];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 Link to comment https://forums.phpfreaks.com/topic/15316-help-mysql-databasephp-help/ Share on other sites More sharing options...
king arthur Posted July 22, 2006 Share Posted July 22, 2006 When you use this syntax[code]mysql_query("INSERT INTO `example1` VALUES ('$name')");[/code]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:[code]mysql_query("INSERT INTO `example1` VALUES (NULL, '$name')");[/code]the NULL will be replaced by the auto-increment value.Or you could use the syntax[code]mysql_query("INSERT INTO `example1` (name) VALUES ('$name')");[/code] Link to comment https://forums.phpfreaks.com/topic/15316-help-mysql-databasephp-help/#findComment-62005 Share on other sites More sharing options...
fenway Posted July 22, 2006 Share Posted July 22, 2006 As a rule, you should never rely on the column order, and always specify the column list for which you are providing values. Link to comment https://forums.phpfreaks.com/topic/15316-help-mysql-databasephp-help/#findComment-62086 Share on other sites More sharing options...
shmickvl Posted July 23, 2006 Author Share Posted July 23, 2006 thanksit worked!!!!!!! yay!!! its been bugging me for hours. im learning mysql/php :)thanks again guys. so simple!!! Link to comment https://forums.phpfreaks.com/topic/15316-help-mysql-databasephp-help/#findComment-62333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.