Forum Moderators: coopster

Message Too Old, No Replies

Added Auto Increment now Insert doesn't work

Php mysql Added Auto Increment now Insert doesn't work

         

razn8

11:29 am on Feb 19, 2009 (gmt 0)

10+ Year Member



I was succesfully inserting form values via PHP to a MySQL table. I added an auto increment id field to the mysql table, now it won't insert.

// Insert data into mysql
mysql_query("INSERT INTO table VALUES ( '$VendorID', '$Type', '$FirstName', '$LastName', '$httpCode' )");

I the PHPmyAdmin it won't let me insert with the auto increment field, ERROR: 1136 Column count doesn't match value count at row 1

whoisgregg

2:17 pm on Feb 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What you will need to do is also send the field names that you are providing values for. Otherwise, mysql doesn't know which value goes in which field. Something like this will work:

mysql_query("INSERT INTO table (`vendor_id`,`type`,`name_first`,`name_last`,`http_code`) VALUES ( '$VendorID', '$Type', '$FirstName', '$LastName', '$httpCode' )");

razn8

2:48 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



I tried that as well and got an error. I'll try it again with your example.

razn8

4:00 pm on Feb 19, 2009 (gmt 0)

10+ Year Member



in phpmyadmin This worked:

INSERT INTO `table` ( `VendorID` , `Type`,`FirstName`,`LastName`,`httpCode` ) VALUES ( '$VendorID', '$Type', '$FirstName', '$LastName', '$httpCode' );

php page this worked:

mysql_query("INSERT INTO table (`VendorID`,`Type`,`FirstName`,`LastName`,`httpCode`) VALUES ( 'VendorID', 'Type', 'FirstName', 'LastName', 'httpCode' )");

It appears my error was the ` vs '

whoisgregg

6:04 pm on Feb 19, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



error was the ` vs '

I bite myself with that all the time. Glad you got it sorted. :)