0
$sql_comp5 ="INSERT INTO `tiquets` (`Id_Tiquet`) VALUES (NULL); SELECT LAST_INSERT_ID()";   
    $result8 = mysql_query($sql_comp5); 

     $flag_control=0;
    while ($row = mysql_fetch_assoc($result8, MYSQL_BOTH)) 
    {
        $flag_control=$flag_control+1;
             $id_t[$flag_control]=$row['LAST_INSERT_ID()'];              
    }


    for ($buc = 1; $buc <=$flag_control; $buc++)
    {
           $id_tiquet=$id_t[$buc];                
    }

I am doing the correct? Or i'm wrong?

Very thanks!!

John Conde
  • 217,595
  • 99
  • 455
  • 496
jordi159
  • 7
  • 6
  • [Please, don't use mysql_* functions in new code](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](http://j.mp/XqV7Lp). See the [red box](http://j.mp/Te9zIL)? Learn about [_prepared statements_](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://j.mp/PoWehJ). – Luigi Siri May 25 '13 at 15:39

2 Answers2

0

You can't do two queries use mysql_* functions. You need mysqli::multi_query() for that. To get the last insert ID using mysql_* use mysql_insert_id():

$sql_comp5 ="INSERT INTO `tiquets` (`Id_Tiquet`) VALUES (NULL);";
$result8 = mysql_query($sql_comp5); 
$id      = mysql_insert_id($result8);
John Conde
  • 217,595
  • 99
  • 455
  • 496
0

Remove the second query - and use php's mysql_insert_id()

$sql_comp5 ="INSERT INTO tiquets (Id_Tiquet) VALUES (NULL)";
$result8 = mysql_query($sql_comp5); $insertedId = mysql_insert_id();

YomY
  • 603
  • 6
  • 16