我正在尝试更新名为customer的数据库中的一些数据。这是我的代码
<?php
Require("dbconnect.php");
$Customer_id = $_POST['Customer_id'];
$Customer_title = $_POST['Customer_title'];
$Customer_forename = $_POST['Customer_forename'];
$Customer_surname = $_POST['Customer_surname'];
$Customer_contact = $_POST['Customer_contact'];
?>
所有变量都保存了正确的数据,因为我测试了它们。 运行此代码时没有收到任何错误,但是它也没有更新数据库?有人可以帮忙吗?提前谢谢!
答案 0 :(得分:2)
字符串常量需要单引号(forename和surname):
$sql = "UPDATE `a6123854_a220559`.`Customer`
SET Customer_forename = '".$Customer_forename."', Customer_surname = '".$Customer_surname."'
WHERE Customer_id = ".$Customer_id."";
请注意,您的代码可能会受到SQL injection的影响。
答案 1 :(得分:1)
有一件小事可能会解决你的问题。它在引文中。
$sql = "UPDATE `a6123854_a220559`.`Customer`
SET Customer_forename='".$Customer_forename."',
Customer_surname='".$Customer_surname."'
WHERE Customer_id='".$Customer_id."'";