0

This is the error i am receiving and this is my code. I am not sure what the error is since line one is only my

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 '' at line 1.

Code:

<?php
$hostname ="localhost";
$db_user = "root";
$db_password = "";
$database = "Special_order_form";
$db_table = "FORMS";
$db = mysql_connect ($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
?>
<html>

<h1><b><center>SPECIAL ORDER/BACK ORDER FORM</center></b></h1>
<body>
<?php 
if (isset($_REQUEST['Submit'])) { 
 $sql = "INSERT INTO $db_table
             (MANUFACTURER, WAREHOUSE, ORDERTYPE, SOLDTO, SHIPFROM, STOREFROM, SHIPMETH, PO, DAY, ACCNT#, CUSTPO, SHIPPINGADDY, SHIPCUSTVIA, SHIPPINGINSTR, FOB, CASHSALE) 
         values('" . mysql_real_escape_string(stripslashes($_REQUEST['MANUFACTURER'])) . "','" . 
            mysql_real_escape_string(stripslashes($_REQUEST['WAREHOUSE'])) . "','" . 
            mysql_real_escape_string(stripslashes($_REQUEST['ORDERTYPE'])) .  "','" . 
            mysql_real_escape_string(stripslashes($_REQUEST['SOLDTO'])) . "','" . 
            mysql_real_escape_string(stripslashes($_REQUEST['SHIPFROM'])) . "','" . 
            mysql_real_escape_string(stripslashes($_REQUEST['STOREFROM'])) . "','" . 
            mysql_real_escape_string(stripslashes($_REQUEST['SHIPMETH'])) . "','" . 
            mysql_real_escape_string(stripslashes($_REQUEST['PO'])) . "','" . 
            mysql_real_escape_string(stripslashes($_REQUEST['DAY'])) . "','" , 
            mysql_real_escape_string(stripslashes($_REQUEST['ACCNT#'])) . "','" , 
            mysql_real_escape_string(stripslashes($_REQUEST['CUSTPO'])) . "','" , 
            mysql_real_escape_string(stripslashes($_REQUEST['SHIPPINGADDY'])) . "','" , 
            mysql_real_escape_string(stripslashes($_REQUEST['SHIPCUSTVIA'])) . "','" , 
            mysql_real_escape_string(stripslashes($_REQUEST['SHIPPINGINSTR'])) . "','" , 
            mysql_real_escape_string(stripslashes($_REQUEST['FOB'])) . "','" , 
            mysql_real_escape_string(stripslashes($_REQUEST['CASHSALE'])) . "')";
if($result = mysql_query($sql ,$db)) { 
echo '<h1>Thank you</h1>Your information has been entered into our database<br><img    src=""'; 
} else 
{ 
echo "ERROR: ".mysql_error(); 
}
} else 
{
?>

<center>
<table border="1">

      <th>MANUFACTURER <br />
   <form method="post" action="">
     <textarea name="MANUFACTURER" cols="20" rows="3" required>
     </textarea><br>
     </th>
    <th>WAREHOUSE #
   <select option="" name="WAREHOUSE"required> 
   <option value="none" selected="selected"></option>
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
   <option value="5">5</option>
    <option value="6">6</option>
   <option value="7">7</option>
   <option value="8">8</option>
   </select>
    </th>
    <th>


   <form action ="">
   <select option="" name="ORDERTYPE"required>
  <option value="none" selected="selected">Select an option</option>
 <option value="Back Order">Back Order</option>
  <option value="Special Order">Special Order</option>
  <option value="Stock Request">Stock Request</option>
  </select>
 </th>


 <th>
 </th>


 <tr>
 </tr>
 <th>SOLD TO</th>
 <th>SHIP FROM FACTORY DIRECT TO:</th>
 <th>ORDER VIA:</th>
 <th>DO NOT WRITE IN THIS BOX <br /> PURCHASING USE ONLY</th>
  <tr>
 <td><form method="post" action="" required>
 <textarea name="SOLDTO" cols="20" rows="9" required>
 </textarea><br>
</td>
<td>
<center>
  <input type="radio" name="SHIPFROM" value="VIKING WAREHOUSE" required> VIKING WAREHOUSE
 <br>
 <input type="radio" name="SHIPFROM" value="AIH STORE"> AIH STORE #<form action ="" required>
  <select option="" name="FROMSTORE">
   <option value="0" selected="selected"></option>
     <option value="1">1</option>
 <option value="2">2</option>
 <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
 <option value="6">6</option>
 <option value="7">7</option>
 <option value="8">8</option>
 </select required>
 <br />
 <input type="radio" name="SHIPFROM" value="CUSTOMER (DROP SHIP)" required> CUSTOMER (DROP SHIP)
 </center>
 </td>
 <td><SELECT MULTIPLE SIZE=10 name="SHIPMETH"required>
  <OPTION VALUE="o1">Next Stock Order
 <OPTION VALUE="o2">TR Trucking
 <OPTION VALUE="o3">Fed Ex- One Day
 <OPTION VALUE="o4">Fed Ex- Second Day
 <OPTION VALUE="o5">Fed Ex- Ground
 <OPTION VALUE="o6">DHL
 <OPTION VALUE="o7">UPS Red(Overnight)
  <OPTION VALUE="o8">UPS Blue(2-Day)
 <OPTION VALUE="o9">UPS Ground
 <OPTION VALUE="o10">Other
 </SELECT></td>


 <td><center>  P.O.    
 <input type="text" name="PO">
 <br>
 DATE: 
 <input type="text" name="DAY">
 </center></td>
 </td>
 <tr>
 <td>ACCOUNT #<br />
  <form method="post" action="">
  </textarea><br><input type="text" name="ACCNT#" required>
  <br/>Customer Purchase<br/> Order # 
 <br/><input type="text" name="CUSTPO">
 </td>
 <td>SHIPPING ADDRESS: <br/>
 <form method="post" action="">
 <textarea name="SHIPPINGADDY" cols="40" rows="5">
  </textarea><br>SHIP TO CUST FROM<br/> AIH VIA 
  <input type="text" name="SHIPCUSTVIA" required>
  </td>
 <td>Special Shipping Instructions<br/><form method="post" action="">
 <textarea name="SHIPPINGINSTR" cols="20" rows="5">
 </textarea><br> 
 </td>
 <td><center>Sell FOB Point<form action="">
 <select name="FOB" required>
 <option value="none" selected="selected">Make A selection</option>
 <option value="Anchorage">Anchorage</option>
 <option value="Factory">Factory</option>
 <option value="Seattle">Seattle</option>
  <option value="Other">Other</option>
 </select>
 </center></td>
 <tr>
 <td>
 CASH SALE
 <input type="checkbox" name="CASHSALE" value="CASH SALE" /><br/>
 COLLECT 50% DEPOSIT
<td></td>
<td></td>
<td>MINIMUM SPECIAL ORDER $50.00
<br/>(Note:  EXCEPT WITH STOCK ORDER<br/> STANDARD PACK QUANTITY<br/> MUST APPLY ON ALL ORDERS)</td>
</table>
 <input type="submit" name="Submit" value="Submit"></center>
 <?php
 }
 ?>
 </form>
 </form>
 </body> 
 </html>

2 Answers 2

2

Try putting ACCNT# in backticks like this `ACCNT#`. For good practice you should enclose your table names and column names in your queries.

You can also echo your $sql variable and inspect the query if you are having problems. Sometimes that can help show the issue.

Sign up to request clarification or add additional context in comments.

Comments

0

For further information, see the sql reference manual here for more information on using special characters such as # in your table names..

An identifier may be quoted or unquoted. If an identifier contains special characters or is a reserved word, you must quote it whenever you refer to it. (Exception: A reserved word that follows a period in a qualified name must be an identifier, so it need not be quoted.)

http://dev.mysql.com/doc/refman/5.1/en/identifiers.html

I personally try to avoid special characters and to have a fixed approach to table names (i.e. either full words or consistent abbreviations) as I find it minimises confusion and mistakes later.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.