[英]Update sql query with PHP and variables
When I run this page, its says You couldnt execute query
. 当我运行此页面时,它表示You couldnt execute query
。 I think there is a syntax problem, but I cannot see the problem. 我认为存在语法问题,但我看不出问题。
The variables look fine when I echo them. 当我回应它们时,变量看起来很好。 I added the column names as a code comment. 我添加了列名作为代码注释。 All the columns are VARCHAR
. 所有列都是VARCHAR
。
I don't believe it is a connection problem since I can perform SELECT AND DELETE
operations from other php
pages. 我不相信这是一个连接问题,因为我可以从其他php
页面执行SELECT AND DELETE
操作。
<?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>
Change your query as follows and it will work 如下更改您的查询,它将工作
$query = "UPDATE customers SET CUST_ID='$id', CUST_FORENAME='$name',
CUST_PHONE='$phone', CUST_SURNAME='$surname' WHERE CUST_ID='$id'";
Thanks guys, It was just a $ sign in one of the column and put back again quotes in the $id > '$id'. 谢谢大家,这只是其中一个列中的$符号,并在$ id>'$ id'中再次放回引号。
$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.";
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.