错误的mysql语法将表单信息上传到数据库
这是我收到的错误,这是我的代码。我不确定错误是什么,因为第一行只是我的
错误:您的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将 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.有关更多信息,请参阅此处的 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..
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.