Jump to content

[SOLVED] Problems inserting data into my database


TGM

Recommended Posts

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

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!! :)

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.