$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);
我想从表中返回列的id,但它返回0。为什么?我该如何解决这个问题?提前致谢
最佳答案
您正在混合 mysql
和 mysqli
函数。变化:
echo $id = mysql_insert_id();
至
echo $id = mysqli_insert_id($con);
<小时/>
您还需要将 mysql_error()
更改为 mysqli_error()
不这样做,不会发出发现任何可能的错误的信号。
关于php - 使用 mysql_insert_id 返回表中列的 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23791953/