错误的mysql语法将表单信息上传到数据库

发布于 2024-12-05 14:41:12 字数 7178 浏览 0 评论 0原文

这是我收到的错误,这是我的代码。我不确定错误是什么,因为第一行只是我的

错误:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行 '' 附近使用的正确语法。

代码:

<?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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听你说爱我 2024-12-12 14:41:12

尝试将 ACCNT# 放在反引号中,例如“ACCNT#”。为了获得良好的实践,您应该将表名和列名括在查询中。

如果遇到问题,您还可以回显 $sql 变量并检查查询。有时这可以帮助显示问题。

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.

攒一口袋星星 2024-12-12 14:41:12

有关更多信息,请参阅此处的 sql 参考手册,了解有关在表名称中使用特殊字符(例如 #)的更多信息。

标识符可以带引号,也可以不带引号。如果一个标识符包含
特殊字符或保留字,无论何时都必须引用它
你参考一下。 (例外:在句点之后的保留字
限定名称必须是标识符,因此不需要加引号。)

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

我个人尝试避免特殊字符并对表名采用固定的方法(即完整的单词或一致的缩写):我发现它可以最大限度地减少混乱以后再犯错误。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文