J M
J M

Reputation: 37

SQL UPDATE not working

I am trying to update some of the data in a database called customer. This is my code

<?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'];

    ?>

all the variables are holding the correct data as I have test echoed them. No errors are recieved when I run this code however it is not updating the database either? Can anyone help? Thank in advance!

Upvotes: 0

Views: 60

Answers (2)

Peter
Peter

Reputation: 9143

There is one little thing that will quite possibly fix your problem. It is in the quotation.

$sql = "UPDATE `a6123854_a220559`.`Customer`
SET Customer_forename='".$Customer_forename."',
Customer_surname='".$Customer_surname."'
WHERE Customer_id='".$Customer_id."'";

Upvotes: 1

Klas Lindb&#228;ck
Klas Lindb&#228;ck

Reputation: 33283

String constants need single quotes (forename and surname):

$sql = "UPDATE `a6123854_a220559`.`Customer` 
SET Customer_forename = '".$Customer_forename."', Customer_surname = '".$Customer_surname."'
WHERE Customer_id = ".$Customer_id."";

Please note that your code may be susceptible to SQL injection.

Upvotes: 2

Related Questions