英文:
Query error: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters
问题
"Does anyone know why my mySQL query gets this error? SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters
try {
$sql = "UPDATE kunder SET fname=?, ename=?, user=? WHERE id = :id";
$stmt = $dbconn->prepare($sql);
$stmt->bindParam(':id', $_SESSION["user_id"]);
$data = array($fname, $ename, $user);
$stmt->execute($data);
} catch (PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}"
英文:
Does anyone know why my mySQL query gets this error? SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters
try {
$sql = "UPDATE kunder SET fname=?, ename=?, user=? WHERE id = :id";
$stmt = $dbconn->prepare($sql);
$stmt->bindParam(':id', $_SESSION["user_id"]);
$data = array($fname, $ename, $user);
$stmt->execute($data);
} catch (PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
答案1
得分: 1
尝试以下翻译代码部分:
try {
$sql = 'UPDATE kunder SET ' .
'fname=:fname,' .
'ename=:ename,' .
'user=:user ' .
'WHERE id = :id';
$stmt = $dbconn->prepare($sql);
$data = array(
'fname' => $fname,
'ename' => $ename,
'user' => $user,
'id' => $_SESSION["user_id"],
);
$stmt->execute($data);
} catch (PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
希望这对你有所帮助。如果你需要进一步的翻译或有其他问题,请随时提出。
英文:
try {
$sql = 'UPDATE kunder SET ' .
'fname=:fname,' .
'ename=:ename,' .
'user=:user ' .
'WHERE id = :id';
$stmt = $dbconn->prepare($sql);
$data = array(
'fname' => $fname,
'ename' => $ename,
'user' => $user,
'id' => $_SESSION["user_id"],
);
$stmt->execute($data);
} catch (PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论