简体   繁体   中英

Return ID of column from table with mysql_insert_id

$sql="INSERT INTO survey (user, title, description, opta, optb,optc,optd,time) VALUES ('$user','$title', '$dis', '$a' , '$b', '$c', '$d','timespan')";
if (mysqli_query($con,$sql))
 {
  echo "Success";
 }
 else
  {
  echo "Error: " . mysql_error();
  }
  echo $id = mysql_insert_id();

mysqli_close($con); 

I want to return id of column from table, but it returns 0. why? and also how can i fix this problem? thanks in advance

You're mixing mysql and mysqli functions. Change:

echo $id = mysql_insert_id();

to

echo $id = mysqli_insert_id($con);

You also need to change mysql_error() to mysqli_error()

Not doing so, will not signal any possible errors found.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM