Jump to content

[SOLVED] Receiving Error Message on SQL Update


ded

Recommended Posts

I am receiving the following error:

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 'desc=Champagne Twist Necklace, category=Necklace, qty=1, cost=20.00, retail=26.00' at line 1

 

 

<?php 
$item = $_GET['item'];
$dbh=mysql_connect ("localhost", "xxxxxxx", "xxxxxxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("xxxxxxx");
$query = "SELECT * FROM inventory WHERE item=$item";
$result = mysql_query($query,$dbh) or die(mysql_error());
while($row = mysql_fetch_array($result))
{
echo "<form action=\"edititem.php?item=$item\" method=\"post\"  enctype=\"multipart/form-data\">";
echo "<strong>Item#: </strong>" . $row['item'] . " 	<br>";
echo "<strong>Description: </strong><textarea name=\"desc\" cols=\"40\" rows=\"1\">" . $row['desc'] . "</textarea><br>";
echo "<strong>Category: </strong><textarea name=\"category\" cols=\"15\" rows=\"1\">" . $row['category'] . "</textarea><br>";
echo "<strong>Qty on Hand: </strong><textarea name=\"qty\" cols=\"5\" rows=\"1\">" . $row['qty'] . "</textarea><br>";
echo "<strong>Cost:</strong> $<textarea name=\"cost\" cols=\"10\" rows=\"1\">" . $row['cost'] . "20.00</textarea><br>";
echo "<strong>Retail: </strong>$<textarea name=\"retail\" cols=\"10\" rows=\"1\">" . $row['retail'] . ".00</textarea><br>";
echo "<input type=\"submit\">";
echo "</form>";
echo "<img src=http://www.website.com/cl/items/" . $row['picture'] . "><br>";
}
?>

 

 

 

<?php 
$item = $_GET['item'];
$desc = $_POST['desc'];
$category = $_POST['category'];
$qty = $_POST['qty'];
$cost = $_POST['cost'];
$retail = $_POST['retail'];
$dbh = mysql_connect ("localhost", "xxxxxxx", "xxxxxxx") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("xxxxxxx");
$insert = "UPDATE inventory SET item=$item, desc=$desc, category=$category, qty=$qty, cost=$cost, retail=$retail WHERE item=$item"; 
$results = mysql_query($insert) or die (mysql_error());
?>

 

Any ideas???

Still does not work....same error

 

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 'desc='Champagne Twist Necklace', category='Necklace', qty='1', cost='20.00', reta' at line 1

 

$insert = "UPDATE inventory SET item='$item', desc='$desc', category='$category', qty='$qty', cost='$cost', retail='$retail' WHERE item='$item'"; 

"desc" is a reserved word in MySQL, you'll need to surround it in backticks (`) - It is good practice to surround your table and field names with backticks, anyway.

 

$insert = "UPDATE `inventory` SET `item`='$item', `desc`='$desc', `category`='$category', `qty`='$qty', `cost`='$cost', `retail`='$retail' WHERE `item`='$item'"; 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.