Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Problem with PHP and MySQL

Name: Fledgling 2007-11-26 1:55

Hello guys, I have to create an order for a shopping cart, and I must recover the ID for that order, so I can use it for the order processing. My problem is that I don't know how to do this. Mind giving me a hand? I'm really stumped here.

Name: Anonymous 2007-11-26 2:00

For example, I insert a new order, but then I have to get the ID generated. And then I do another insert with that ID, whose I have to get the ID for that one as well.

Name: Anonymous 2007-11-26 2:07

Ah, silly me. :)

Here is how.

<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db('mydb');

mysql_query("INSERT INTO mytable (product) values ('kossu')");
printf("Last inserted record has id %d\n", mysql_insert_id());
?>


Hehe. Must pay more attention next time. Thanks anyway guys.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List