此代码将从另一个PHP代码接收id和区域,并且我确信它已正确接收它们。此代码用于更新id等于用户输入的id的区域。我运行代码,我从这个语句中得到了SQL语法错误。
$sql = "UPDATE complain SET area = ".$area."WHERE num = ".$id."";
任何人都知道出了什么问题?
<?php
$area = $_GET['area'];
$id = $_GET['id'];
echo $area;
echo $id;
//$Area = $_POST['variable'];
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "sfa";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "UPDATE complain SET area = ".$area."WHERE num = ".$id."";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
答案 0 :(得分:1)
在Where子句之前添加一些空格,使您的查询像
UPDATE complain SET area = ".$area." WHERE num = ".$id."
答案 1 :(得分:1)
".$area."WHERE
结果是
UPDATE complain SET area = 2WHERE num = 0815
答案 2 :(得分:0)
尝试使用此查询。它工作正常并更新记录 -
&#34;更新投诉SET区=&#39;。$ area。&#39; WHERE num =&#39;。$ id。&#39;&#34;
答案 3 :(得分:0)
以下查询应该有效:
$scope.addCart = function() {
$http({
method : 'POST',
url : 'server/menu/add_cart',
headers : { 'Content-Type' : 'application/json' },
data : JSON.stringify({ id: $scope.id ,menu: $scope.menu , harga:$scope.harga })
}).success(function(data) {
console.log(data);
});
}
希望它有所帮助!