Reputation: 347
When I run this page, its says 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
.
I don't believe it is a connection problem since I can perform SELECT AND DELETE
operations from other php
pages.
<?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>
Upvotes: 1
Views: 8910
Reputation: 340
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'";
Upvotes: 3
Reputation: 347
Thanks guys, It was just a $ sign in one of the column and put back again quotes in the $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.";
?>
Upvotes: 1