php中for和sql更新的正确语法是什么?

oyt4ldly  于 2021-06-24  发布在  Mysql
关注(0)|答案(3)|浏览(362)

我正在尝试使用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>

感谢您的帮助。谢谢您!

pdsfdshx

pdsfdshx1#

试一下下面的代码

UPDATE CustomerDetails SET `Follow Up` = '".$follow."' WHERE Email = '".$email_follow."'
cigdeys3

cigdeys32#

需要使用点运算符,并且需要使用勾号而不是单引号
勾选- Follow Up -正确。

$query = "UPDATE CustomerDetails
    SET `Follow Up` = '".$follow."'
    WHERE Email = '".$email_follow."'";

$update = mysqli_query($dbconn, $query);
axr492tv

axr492tv3#

你的表属性 Follow Up 有一个空格,你需要加`来 Package 它
所以改变吧

UPDATE CustomerDetails SET Follow Up = '$follow' WHERE Email = '$email_follow'

UPDATE CustomerDetails SET `Follow Up` = '$follow' WHERE Email = '$email_follow'

相关问题