Forum Moderators: coopster

Message Too Old, No Replies

mysql insert id returning 0

         

paulmadillo

8:28 am on Apr 14, 2008 (gmt 0)

10+ Year Member



Hi.

I'm writing a shopping cart and I need to receive the ID of the order that has just been inserted.

Obviously I've used mysql_insert_id and I've put it AFTER the insert query. The insert works fine and the order_id field is incrementing fine but mysql_insert_id still returns '0'.

Does anyone know what the problem might be?

Here's the code...


$insertOrder = "INSERT INTO orders (*Field Names Here) VALUES (*Variables Here*)";

$insertOrder_q = mysql_query($insertOrder, $connect) or die (mysql_error()); // This inserts the order and auto_increments fine

echo mysql_insert_id(); // This always returns 0

coopster

12:45 pm on Apr 14, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



How does mysql_insert_id work? [webmasterworld.com]

turbosaab

9:44 pm on Apr 14, 2008 (gmt 0)

10+ Year Member



Try:
echo mysql_insert_id($connect);

Hope that helps.

coopster

12:06 am on Apr 16, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Actually I think you will find that function less useful than expected; have a look at that link I mentioned.