我正在尝试使用html和php更新数据库中的条目。但是,我一直收到错误消息,说我的sql语法错误。
这是php文件中的代码:
<?php
$server = "127.0.0.1";
$dbUsername = "root";
$dbPassword = "";
//create connection
$dbconn = new mysqli($server, $dbUsername, $dbPassword, $dbname);
$email_follow = $_POST['email_follow'];
$follow = $_POST['follow'];
$update = mysqli_query($dbconn, "UPDATE CustomerDetails SET Follow Up = '$follow' WHERE Email = '$email_follow'");
if ($dbconn->query($update) === TRUE) {
echo "Record updated successfully";
} else {
echo "Error updating record: " . $dbconn->error;
}
?>
这是html表单:
<form action="cust_details_followup.php" method="post">
Email:
<input type="email" name="email_follow" id="email_follow">
Enter Follow Up Details:
<input type="text" name="follow" id="follow">
<input type="submit" value="Update">
</form>
感谢您的帮助。谢谢!
答案 0 :(得分:2)
您的表格属性Follow Up
有一个空格,您需要添加`来包装它
所以改变
UPDATE CustomerDetails SET Follow Up = '$follow' WHERE Email = '$email_follow'
到
UPDATE CustomerDetails SET `Follow Up` = '$follow' WHERE Email = '$email_follow'
答案 1 :(得分:0)
需要使用点运算符,并且需要使用刻度线而不是单引号
勾选-
Follow Up
-正确。
$query = "UPDATE CustomerDetails
SET `Follow Up` = '".$follow."'
WHERE Email = '".$email_follow."'";
$update = mysqli_query($dbconn, $query);
答案 2 :(得分:0)
尝试以下代码
UPDATE CustomerDetails SET `Follow Up` = '".$follow."' WHERE Email = '".$email_follow."'