0
我試圖解決這個查詢時遇到了一點問題,如果在表單輸入後單擊提交按鈕,這是一個頁面上'必需'的腳本。該頁面已經設置了$ connection變量,並且值正確回顯,儘管在第二個嵌套的「IF」語句中我仍然收到「錯誤」消息。誰能幫忙?謝謝!MySQLi新手,UPDATE查詢時出錯?
<?php
if ($_POST['firstname'] != "" && $_POST['lastname'] != "" && $_POST['email'] != "" && $_POST['position'] != "" && $_POST['building'] != "") {
$iserid = htmlspecialchars($_COOKIE['userid']);
$fname_input = htmlspecialchars($_POST['firstname']);
$lname_input = htmlspecialchars($_POST['lastname']);
$fullname_input = htmlspecialchars($_POST['firstname']) . " " . htmlspecialchars($_POST['lastname']);
$email_input = htmlspecialchars($_POST['email']);
$position_input = htmlspecialchars($_POST['position']);
$building_input = 1;
$update = $connection->prepare("UPDATE user SET first = ?, last = ?, full = ?, email = ?, position = ?, building = ? WHERE id = ?") or trigger_error($connection->error);
$update->bind_param("ssssssi",$fname_input, $lname_input, $fullname_input, $email_input, $position_input, $building_input, $userid);
if ($update->execute) {
echo "success";
$update->close();
} else {
echo "fail";
$update->close();
}
} else {
$error = "One or more of your fields was left blank. Please press back on you browser toolbar and try again or click here to close this message.";
}
?>
有很多原因造成的失敗。你應該在PHP日誌文件中獲得一些東西。 –
是否所有的表單域都使用正確的'name ='屬性進行更正? (注意 - 你不應該用'htmlspecialchars()'在數據庫中存儲值,這是一個_output_消毒方法,當你試圖搜索你的表時,如果它們的數據已被修改,它可能會導致你未來的問題。 –
我認爲''更新 - >執行()'你忘了'()' –