Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

auto_increment

Status
Not open for further replies.

inusrat

Programmer
Feb 28, 2004
308
CA
Hi,

I have a table in which I have 6 fields, my primary key called order_no is bigint and it is also auto_incrment.

My insert statement is like the following. It does not work

$resultcat= mysql_query("insert into shopping_cart values ('$cart_id','$productid','$name','$quantity','$price' )")

Now If take my order_no (auto increment) key out, it works, what I am doing wrong in my insert statement?

Thanks



 
Your insert statement only has five fields whilst your table has six fields.

Assuming that your auto_increment field, order_no, is the first column in the table then your insert statement should look like:
Code:
$resultcat= mysql_query("insert into shopping_cart  values (0,'$cart_id','$productid','$name','$quantity','$price' )")
MySQL will replace the 0 with the appropriate value for order_no when it inserts the record into your table.


Andrew
Hampshire, UK
 
or in your insert, identify the db fields that you want to populate, ignore the autoincrement.

keep in mind that on some of the versions, auto-increment does not work in multitasking situations.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top