我有一個帶有文本輸入字段的表單& select下拉菜單,它將信息提交給profile-updated.php。它作爲一個簡單的UPDATE查詢工作,但我試圖使它成爲參數化查詢,它不起作用。它不會給我一個錯誤,它只是不實際更新任何東西。我爲參數化的SELECT或INSERT查詢做了一個教程,所以我試圖使它適合我的UPDATE需求時使用「$ _POST ['age'];一部分。任何幫助極大的讚賞。文本輸入的參數化查詢
下面是參數化嘗試查詢代碼:
$age = $_POST['age'];
$gender = $_POST['gender'];
$videourl = $_POST['videourl'];
$soundcloud = $_POST['soundcloud'];
$about = $_POST['about'];
$facebook = $_POST['facebook'];
$twitter = $_POST['twitter'];
$stmt = $con->stmt_init();
if ($stmt->prepare("UPDATE Users1 (age, gender, videourl, soundcloud,
about, facebook, twitter) VALUES (?, ?, ?, ?, ?, ?, ?) WHERE email = '" . $_POST['email'] . "' ")) {
$stmt->bind_param("sssssss", $age, $gender, $videourl, $soundcloud, $about, $facebook, $twitter);
$stmt->execute();
$stmt->close();
}
$con->close();
這裏是一個優良的工作我的舊更新代碼:
$sql = mysqli_query($con, "UPDATE Users1
SET age = '" . $_POST['age'] . "',
gender = '" . $_POST['gender'] . "',
videourl = '" . $_POST['videourl'] . "',
soundcloud = '" . $_POST['soundcloud'] . "',
about = '" . $_POST['about'] . "',
facebook = '" . $_POST['facebook'] . "',
twitter = '" . $_POST['twitter'] . "',
WHERE email = '" . $_POST['email'] . "'
");
爲什麼不綁定電子郵件參數?如果你不這樣做,你仍然在用不可信數據構建一個SQL命令。 –