TGM Posted May 3, 2009 Share Posted May 3, 2009 I working on a small restaurant database where I can keep track of the orders. I want to same all the orders into the database but for some reason I keep getting -->"" 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 'order(quantity) VALUES('3')' at line 1""" The code below is jus trying the save the quantity into the database. I am using WAMP 5 <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: loginpage.php"); } ?> <?php $hostname = "localhost"; $db_user = "root"; $db_password = ""; $database = "users"; $db_table = "order"; $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db($database,$db); ?> <html> <body> <?php if (isset($_REQUEST['Submit'])) { $sql="INSERT INTO $db_table(quantity) VALUES('".mysql_real_escape_string(stripslashes($_REQUEST['quantity']))."')"; if($result = mysql_query($sql ,$db)) { echo '<div align="center"><h1>Thank you</h1>YOUR ORDER IS NOW COMLETED<br><br></div>'; } else { echo "ERRORrRrRrR: ".mysql_error(); } } else { ?> <form method="post" id="form"> <table border=1> <tr> <td>Food Category</td> <td>Food Item</td> <td>Price per Unit</td> <td>Quanitiy</td> </tr> <tr> <td><select name="" class="form" style="width:160px;"></select></td> <td><select name="" class="form" style="width:160px;"></select></td> <td><select name="" class="form" style="width:160px;"></select></td> <td><select name="quantity" class="form" > <option value="1">1 <option value="2">2 <option value="3">3 </select></td> <td><input type="text" name="extra" class="form" /></td> <td><input type="button" value="Reset" onclick="resetListGroup('food')"> </td> <td><input type="Submit" name="Submit" value="Submit" </td> </tr> </table> </form> <?php } ?> </body> </html> I have use this same method in an previous database before and works but doesn't work with this one Link to comment https://forums.phpfreaks.com/topic/156607-solved-problems-inserting-data-into-my-database/ Share on other sites More sharing options...
PFMaBiSmAd Posted May 3, 2009 Share Posted May 3, 2009 Order is a reserved mysql keyword, as in ORDER BY. I recommend you rename your table to something else. Link to comment https://forums.phpfreaks.com/topic/156607-solved-problems-inserting-data-into-my-database/#findComment-824609 Share on other sites More sharing options...
Ken2k7 Posted May 3, 2009 Share Posted May 3, 2009 $sql="INSERT INTO `$db_table` (`quantity`) VALUES('".mysql_real_escape_string(stripslashes($_REQUEST['quantity']))."')"; You need the backticks so MySQL doesn't treat it as a keyword. Link to comment https://forums.phpfreaks.com/topic/156607-solved-problems-inserting-data-into-my-database/#findComment-824614 Share on other sites More sharing options...
TGM Posted May 3, 2009 Author Share Posted May 3, 2009 Order is a reserved mysql keyword, as in ORDER BY. I recommend you rename your table to something else. yeah i figured it out..the error was on my table/mysql...I drop the table and created it again and name it orders (with the "s") and is working. On the previous "order" table I didn't had a primary key, so I thought that was the problem but now as you explained word "Order" was the problem..THANKS very much!! Link to comment https://forums.phpfreaks.com/topic/156607-solved-problems-inserting-data-into-my-database/#findComment-824679 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.