当我运行此页面时,它会显示You couldnt execute query
。我认为存在语法问题,但我看不出问题。
当我回应它们时,变量看起来很好。我添加了列名作为代码注释。所有列都是VARCHAR
。
我不相信这是一个连接问题,因为我可以从其他SELECT AND DELETE
页面执行php
操作。
<?php
$id = $_POST["id"];
$name = $_POST["name"];
$surname = $_POST["surname"];
$phone = $_POST["phone"];
/* Table in the DDBB(all are VARCHAR): CUST_ID CUST_FORENAME CUST_PHONE CUST_SURNAME*/
$query = "UPDATE customers SET CUST_ID='$id',$CUST_FORENAME='$name',
CUST_PHONE='$phone', CUST_SURNAME='$surname' WHERE CUST_ID=$id";
$result = mysqli_query ($connection,$query)
or die ("You couldn’t execute query");
echo "<br /><br />User $id has been updated.";
?>
</div>
</body>
</html>
答案 0 :(得分:2)
按如下所示更改您的查询,它将起作用
$query = "UPDATE customers SET CUST_ID='$id', CUST_FORENAME='$name',
CUST_PHONE='$phone', CUST_SURNAME='$surname' WHERE CUST_ID='$id'";
答案 1 :(得分:1)
谢谢大家,这只是其中一个专栏中的$符号,并在$ id&gt;中再次放回引号&#39; $ ID&#39;
$id = $_POST["id"];
$name = $_POST["name"];
$surname = $_POST["surname"];
$phone = $_POST["phone"];
/*CUST_ID CUST_FORENAME CUST_PHONE CUST_SURNAME*/
$query = "UPDATE customers SET CUST_ID='$id',CUST_FORENAME='$name',
CUST_PHONE='$phone', CUST_SURNAME='$surname' WHERE CUST_ID='$id'";
$result = mysqli_query ($connection,$query)
or die(mysqli_error($connection));
echo "<br /><br />User $id has been updated.";
?>