我试图更新特定用户的生物列,但我得到一个新的行。通过类似的问题,但不知道我的情况。mysql创建一个新的行而不是更新现有的
if (isset($_SESSION['logged_in']) && $_SESSION['name_of_user'] == $profile_name) {
$pageOwner = true;
}
if (isset($_POST['submit'])) {
$bio = $_POST['bio'];
if (empty($bio)) {
$error = "Missing Bio";
} else {
if ($member_bio->num_rows == 1) {
if ($query = $db->query("UPDATE user_account SET 'bio'='$bio' WHERE 'id_user'='$id'")) {
$ok_mesg = "Profile has been updated!!!";
} else {
$error = "ERROR on our end";
}
} else {
if ($query = $db->query("INSERT INTO user_account (bio) VALUES('$bio')")) {
$ok_msg = "Profile has been updated";
} else {
$error = "Error on our end";
}
}
}
}
** **警告你的代码可能会受到SQL注入攻击! –
修复您的缩进。 –
并添加if语句的其余部分 – Chandu