ded Posted October 7, 2009 Share Posted October 7, 2009 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??? Quote Link to comment https://forums.phpfreaks.com/topic/176869-solved-receiving-error-message-on-sql-update/ Share on other sites More sharing options...
mikesta707 Posted October 7, 2009 Share Posted October 7, 2009 try surrounding strings with single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/176869-solved-receiving-error-message-on-sql-update/#findComment-932577 Share on other sites More sharing options...
ded Posted October 7, 2009 Author Share Posted October 7, 2009 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'"; Quote Link to comment https://forums.phpfreaks.com/topic/176869-solved-receiving-error-message-on-sql-update/#findComment-932578 Share on other sites More sharing options...
zq29 Posted October 7, 2009 Share Posted October 7, 2009 "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'"; Quote Link to comment https://forums.phpfreaks.com/topic/176869-solved-receiving-error-message-on-sql-update/#findComment-932584 Share on other sites More sharing options...
mikesta707 Posted October 7, 2009 Share Posted October 7, 2009 it seems like qty and cost are numeric columns . you dont need to surround numeric columns with single quotes Quote Link to comment https://forums.phpfreaks.com/topic/176869-solved-receiving-error-message-on-sql-update/#findComment-932586 Share on other sites More sharing options...
ded Posted October 7, 2009 Author Share Posted October 7, 2009 Excellent.....I did not know that. Thank you. Works perfect now. Quote Link to comment https://forums.phpfreaks.com/topic/176869-solved-receiving-error-message-on-sql-update/#findComment-932588 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.