Problem with mysql function mysqli_insert_id()

Asked

Viewed 46 times

0

I have the following query:

$ad="INSERT INTO comanda_aberta set numero='$a', data_abertura=NOW(), data_fechamento=NULL";

mysqli_query($con,$ad);      
$idcomandalast = mysqli_insert_id($con);

when I print the variable $idcomandalast it always returns empty. and in the database the Insert information is being recorded normally. someone can help me in this problem?

  • Does your database use autoincrement? Test like this mysqli_query($con,$ad) or die(mysqli_error($con)); $idcomandalast = mysqli_insert_id($con); var_dump($idcomandalast);

  • return this Aki D: www server bar Sig pages 4 commands.php:10:int 10

  • So it seems that returned correctly int 10, you must be overwriting the variable elsewhere in the script

  • Then I realized this just that I commented on the var_dump line and gave an echo $idcomandalast; and it returned.

  • As I said, your variable is being affected by something, probably being overly sensitive, has how to post more code?

  • face what I’m finding strange he that don’t have Cod, only the connection with db , if I give a print_r or var dump it shows the id if I give an echo or print it doesn’t show.

  • You’re not messing with Buffer, are you?

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.