Menu
Hi All,
The following script adds a record to my orders table and then re-queries for it’s ID:
[code=php]$q = “INSERT INTO orders (fields_here) VALUES (values_here)”;
query_database($q);
$q = “SELECT MAX(id) AS id FROM orders”;
$result = query_database($q);
$row = mysql_fetch_array($result);
echo $row[‘id’];
The problem I’m having is that sometimes the ID returned is 1 less than I’m expecting. For example, I might get an ID of 30000 when I’m expecting 30001.
I’ve tried tweaking the SELECT query but no success.
Does anyone have any others ideas about what’s going wrong?
—
Thanks,
dai.hop