Php 菲律宾元';t从数据库返回整个值

Php 菲律宾元';t从数据库返回整个值,php,html,mysql,Php,Html,Mysql,我目前正在处理一个在线订单,遇到了一个非常奇怪的问题。 我有一个下拉菜单,其中的选项是数据库表中某一列的值。以下是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

我目前正在处理一个在线订单,遇到了一个非常奇怪的问题。 我有一个下拉菜单,其中的选项是数据库表中某一列的值。以下是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>

项目名称
项目SKU
量
特别说明
单价
总价

在HTML中引用值,并转义数据

print "<option value=$p>".$p."</option>";
打印“$p.”;
致:

打印“.htmlspecialchars($p)”;
我更喜欢这样写:

$p = htmlspecialchars($p);
printf('<option value="%s">%s</option>', $p, $p);
$p=htmlspecialchars($p);
printf('%s',$p,$p);
您只得到第一部分,因为这是字符串中第一个空格之前的全部内容,浏览器将其解释为值,其余部分解释为语法错误

因此,HTML中的所有属性值都应引用:

<tag stringproperty="value" integerproperty="42"></tag>

如果你想变得非常严格,唯一允许的引号是双引号


然而,大多数浏览器都或多或少地以一种永久性的“怪癖”模式运行,并接受/呈现各种违反HTML的标准,因为“这就是一直以来的做法”。

警告您的代码极易受到sql注入攻击!!!好啊因为我是新来的自学成才的,所以我不确定sql注入攻击到底是什么,但谢谢!我将尝试使用
PDO
mysqli.*
函数查找outStart,并在来回发送数据之前绑定您的值。通过这种方式,您将能够防止大多数注入漏洞
mysql.*
函数已被正式弃用,不建议使用它!非常感谢。我没想到那个部分会有问题,因为我以前做过同样类型的编码,效果很好。。
$p = htmlspecialchars($p);
printf('<option value="%s">%s</option>', $p, $p);
<tag stringproperty="value" integerproperty="42"></tag>