【发布时间】:2014-11-01 00:17:30
【问题描述】:
我目前正在处理在线订单,遇到了一个非常奇怪的问题。 我有一个下拉菜单,哪些选项是数据库表中某一列的值。这是html代码:
<form name="form" method="post" action="placedOrder.php"><table width="70%" border="5" align="center"><tr>
<th scope="row">Item Name</th>
<th scope="row">Item SKU</th>
<th scope="row">Quantity</th>
<th scope="row">Special Note</th>
<th scope="row">Unit Price</th>
<th scope="row">Total Price</th></tr><tr>
<th scope="row">
<?php
include('connect.php');
$result = mysql_query("SELECT description FROM products")
or die(mysql_error());
print "<select name='description' value='description'>";
print "<option value='' disabled selected>Please Select A Product</option>";
while ($info = mysql_fetch_array($result))
{
$p = $info["description"];
print "<option value=$p>".$p."</option>";
}
print "</select>";
?>
</th>
<th scope="row"><input name="sku_1" id="sku_1" readonly /></th>
<th scope="row"><input name="qty_1" /></th>
<th scope="row"><input name="note_1" /></th>
<th scope="row"><input name="uPrice_1" id="uPrice_1" readonly /></th>
<th scope="row"><input name="tPrice_1" readonly /></th></tr></table><input type="submit"/></form>
当我要处理placedOrder.php 以从html 中返回值并存储到数据库中时,我一直让页面返回空白并且没有任何显示。我发现原因可能是“描述”部分。您可能会在以下代码中看到:
<?php
include('connect.php');
$p = $_POST['description'];
echo $p;
$result = mysql_query("SELECT sku_id, unit_price FROM products WHERE description='{$_POST['description']}'")
or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
echo $row[0];
echo $row[1];
}
?>
$_POST['description'];部分应该从数据库中返回我的产品名称,它是“48X72 CORDLESS BLACKOUT CELLULAR SHADE 9/16”WHITE”但是在我回显它后只返回“48X72”,其余的值都消失了。我错过了代码中的任何内容吗?
【问题讨论】:
-
警告您的代码极易受到 sql 注入攻击!!!
-
好的...因为我是新手并且是自学的,所以我不确定sql注入攻击到底是什么,但谢谢!我会试着找出答案
-
开始使用
PDO或mysqli_*函数并在来回发送数据之前绑定您的值。通过这种方式,您将能够防止大多数注入漏洞。mysql_*函数已正式弃用并且不推荐使用