0

In PHP 4, how can I easily get the last id after an insert in db? For example:

$queryInsert = "INSERT INTO `table` (`id`, `info`) VALUES (NULL, '".$INFO_VAR."');";

mysql_query($queryInsert) or die (mysql_error());
giosans
  • 1,136
  • 1
  • 12
  • 30
NicoESIEA
  • 499
  • 1
  • 6
  • 23
  • 2
    Do you really mean *Php 4*? – Nigel Ren Jan 11 '19 at 15:20
  • 1
    https://secure.php.net/manual/en/function.mysql-insert-id.php – aynber Jan 11 '19 at 15:20
  • 2
    Worth having a read - https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php. – Nigel Ren Jan 11 '19 at 15:24
  • Use `$insert_id= mysql_insert_id();` – Pritamkumar Jan 11 '19 at 15:26
  • Yes I know :( Php4.... Ok perfect, mysql_insert_id() returned the last value generated by auto-increment... But how can I be sure this id will be the one concerned by my insert? I mean, is it possible to have to insert by two different users at the same time (or very very closed) Which will return for both of them the same last id... (the newest one)? – NicoESIEA Jan 11 '19 at 15:28
  • No need of name and regards in the question. – giosans Jan 11 '19 at 15:31
  • If you're running PHP 4 on a production server you've got some huge problems. This is a security risk that's alarmingly severe, *especially* because you probably have an untold number of high-risk [SQL injection bugs](http://bobby-tables.com/). – tadman Jan 11 '19 at 17:20
  • However, it looks better to use mysqli since this one is newer and my is deprecated :( – NicoESIEA Jan 18 '19 at 14:49

1 Answers1

0

use mysql_insert_id();, you find the doc here

Ass3mbler
  • 3,855
  • 2
  • 20
  • 18