Hi,
I was wondering if anyone could possibly help me. I have managed to retrieve individual rows into a form. Some fields are editable so that i can change the quantity etc. However, when i come to pressing the update button i get the following error message
Update Failed: 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 id = ‘1"’’ at line 2
My code is as follows:
<title>Edit Car Details</title>
<link href="css/adminmain.css" rel="stylesheet" type="text/css" />
[php]
<?php // Connecting to db for ODE Test Script update require_once "dbc.php"; mysql_select_db ("prestigesupercars"); //initiating variable: id the system is either getting the information or posting the information held on the database. //i used the get and post function because the user would like to see the latest updates if any fields are changed when they //are on the form. if(isset($_GET['id'])) $id = mysql_real_escape_string($_GET['id']); else $id = mysql_real_escape_string($_POST['id']); $msg = ""; $sql = "SELECT * FROM cars WHERE id = '".$id."'"; $find = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($find) != 0 ){ $r = mysql_fetch_array($find); } else { die("No record found for car ID number"); } //process updates if(isset($_POST['update'])) { $id = $_POST['id']; $ud = array(); //This is where the system returns all the updated fields into the database and updates the database $sql = "UPDATE cars SET Car_Name = '" . $_POST['ncar'] . "', Price = '" . $_POST['ncarp'] . "', Quantity = '" . $_POST['nq'] . "', WHERE id = '" . $id . "';"; $qry = mysql_query($sql); if($qry) { $msg = "Car Details Updated Click here to go back"; } else { $msg = "Update Failed: ".mysql_error(); } } $sql = "SELECT * FROM cars WHERE id = '".$id."'"; $find = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($find) != 0 ){ $r = mysql_fetch_array($find); } else { die("No record found for car ID number"); } ?>[/php]
Car Id:Car Name: Car Price: Quantity: