Hello, having some issues in updating. This is my update php. The "isset get customersID) is fine, as it retrieves information from the selected user. However, when I click “update” it gives me an error. The problem lies in my updating query/code.
Here’s the exact line error after executing the update button: “You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE customerID=‘1045’’ at line 1”.
Just need to know how to fix it. I’ll still work on it, but any help is really appreciated.
[php]<?php include ‘…/view/header.php’;
include ( “connect.php”);?>
if(isset($_GET[‘customerID’]))
{
$customerID = $_GET[‘customerID’];
if (isset($_POST[“edit”]))
{
$update = " UPDATE customers SET “;
$update .= sprintf(” firstName =’%s’ ," , mysql_real_escape_string( $_POST[‘firstName’]));
$update .= sprintf(“lastName = ‘%s’ ,” , mysql_real_escape_string($_POST[‘lastName’]));
$update .= sprintf(“address = ‘%s’ ,” , mysql_real_escape_string($_POST[‘address’]));
$update .= sprintf(“city = ‘%s’ ,” , mysql_real_escape_string($_POST[‘city’]));
$update .= sprintf(“state = ‘%s’ ,” , mysql_real_escape_string($_POST[‘state’]));
$update .= sprintf(“postalCode = ‘%s’ ,” , mysql_real_escape_string($_POST[‘postalCode’]));
$update .= sprintf(“countryCode = ‘%s’ ,” , mysql_real_escape_string($_POST[‘countryCode’]));
$update .= sprintf(“phone = ‘%s’ ,” , mysql_real_escape_string($_POST[‘phone’]));
$update .= sprintf(“email = ‘%s’ ,” , mysql_real_escape_string($_POST[‘email’]));
$update .= sprintf(“password = ‘%s’ ,” , mysql_real_escape_string($_POST[‘password’]));
$update .= “WHERE customerID=’$customerID’”;
mysql_query($update) or die (mysql_error() );
}
$sql = “SELECT * FROM customers WHERE customerID =$customerID”;
$result=mysql_query($sql);
if (mysql_num_rows($result)== 1){
$row = mysql_fetch_assoc($result);
?>
View/Update Customer
First Name:<input type ="text" name ="firstName" value ="<? echo $row['firstName'] ?>"/> <br />
Last Name:<input type ="text" name ="lastName" value ="<? echo $row['lastName'] ?>"/> <br />
address:<input type ="text" name ="address" value ="<?php echo $row['address'] ?>"> <br />
city:<input type ="text" name ="city" value ="<?php echo $row['city'] ?>"> <br />
state:<input type ="text" name ="state" value ="<?php echo $row['state'] ?>"> <br />
country code:<input type ="text" name ="countryCode" value ="<?php echo $row['countryCode'] ?>"> <br />
postal code:<input type ="text" name ="postalCode" value ="<?php echo $row['postalCode'] ?>"> <br />
phone:<input type ="text" name ="phone" value ="<?php echo $row['phone'] ?>"> <br />
email:<input type ="text" name ="email" value ="<?php echo $row['email'] ?>"> <br />
password:<input type ="text" name ="password" value ="<?php echo $row['password'] ?>"> <br />
<input type ="submit" name ="submit" value ="Update">
<input type ="hidden" name ="edit" value ="1">
</form>
<?php
}
}
?>