Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php: mysql_insert_id() issues [duplicate]

Tags:

php

mysql

Hi guys I was hoping from some help here, please.

I have a INSERT query to a table, after this is done I am calling:

mysql_insert_id();

In order to send the last ID inserted into the table to the next page like this:

$insertGoTo = "confirm_booking.php?booking_ID=" .$_POST['booking_ID']. "";

Unfortunately it does not work, all I get is a zero.

The table I am inserting into has an auto increment number and values are inserted into it.

I have also tried SELECT MAX(id) FROM mytable. This dosn't work neither.

I know that this problem has been talked about already. I read all posts but nothing came useful.

Many thanks Francesco

like image 354
frapet Avatar asked Dec 18 '25 06:12

frapet


1 Answers

You have to use the value returned by MySql_Insert_Id () when you generate your link:

// your query
$newId = MySql_Insert_Id ();

$insertGoTo = "confirm_booking.php?booking_ID=" . $newId;
like image 152
Jan Hančič Avatar answered Dec 20 '25 21:12

Jan Hančič