gpt4 book ai didi

php - 使用 mysql_insert_id 返回表中列的 ID

转载 作者:行者123 更新时间:2023-11-29 12:57:41 25 4
gpt4 key购买 nike

$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。为什么?我该如何解决这个问题?提前致谢

最佳答案

您正在混合 mysqlmysqli 函数。变化:

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com