所以我正在尝试为我的公司设置一个简单的出勤网络应用程序。 checkin / checkout 是通过一个按钮完成的,为了做到这一点,我几乎同时进行了插入和更新。 但是要进行适当的更新,我需要一个“bind_param”的“id”,我有点卡在那里。我敢打赌这是一个简单的问题,但我找不到解决方法。
if ($pre == 0) {
$sql = $mysqli->prepare("INSERT INTO presence(code_pr,heure_debut,user_id)
VALUES( ? , ? , ? )
") or die(mysqli_error($mysqli));
$sql->bind_param("sss", $code_pr, $heure_debut, $idcompte);
if (!$sql->execute()) {
die('<h3 style="color:red;" align="center">ERREUR</h3>' . mysqli_error($mysqli));
}
} else {
if ($pre == 1 && $precheck == 1) {
$sqlsrt = $mysqli->prepare("UPDATE presence SET heure_fin=? WHERE user_id=? AND id=?") or die(mysqli_error($mysqli));
$sqlsrt->bind_param('ss', $heure_fin, $idcompte);
if (!$sqlsrt->execute()) {
die('<h3 style="color:red;" align="center">ERREUR</h3>' . mysqli_error($mysqli));
}
}
}
我希望能够有一个 id 放入我的“bind_param”中。
最佳答案
我认为“$conn->lastInsertId()”会有所帮助。
if (!$sql->execute()) {
die('<h3 style="color:red;" align="center">ERREUR</h3>' .
mysqli_error($mysqli));
}else{
//Here you can take the ID of the last Insert
$id = $conn->lastInsertId()
}
关于php - 如何在没有 "bind_param"的情况下进行更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56887618/