我有一个带有文本输入字段和选择下拉列表的表单,它将信息提交到 profile-updated.php。它作为一个简单的 UPDATE 查询工作,但我试图将它变成一个参数化查询,但它不起作用。它不会给我一个错误,它实际上并没有更新任何东西。我为参数化的 SELECT 或 INSERT 查询做了一个教程,所以在尝试使用“$_POST['age'];”使其适合我的 UPDATE 需求时,我可能搞砸了。部分。非常感谢任何帮助。
这是尝试的参数化查询代码:
$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'] . "'
");