php mysql_fetch_array 是否适用于 html 输入框?
这是我的整个PHP代码:
<?php if(empty($_POST['selid']))
{echo "no value selected"; }
else
{
$con = mysql_connect("localhost","root","");
if(mysql_select_db("cdcol", $con))
{
$sql= "SELECT * FROM products where Id = '$_POST[selid]'";
if($result=mysql_query($sql))
{
echo "<form name=\"updaterow\" method=\"post\" action=\"dbtest.php\">";
while($row = mysql_fetch_array($result))
{
echo "Id :<input type=\"text\" name=\"ppId\" value=".$row['Id']." READONLY></input></br>";
echo "Name :<input type=\"text\" name=\"pName\" value=".$row['Name']."></input></br>";
echo "Description :<input type=\"text\" name=\"pDesc\" value=".$row['Description']."></input></br>";
echo "Unit Price :<input type=\"text\" name=\"pUP\" value=".$row['UnitPrice']."></input></br>";
echo "<input type=\"hidden\" name=\"mode\" value=\"Update\"/>";
}
echo "<input type=\"submit\" value=\"Update\">";
echo "</form>";
}
else {echo "Query ERROR";}
}
}
?>
问题这里是,...如果我使用mysql_fetch_array($result)
从数据库获取的值是这样的:(说描述是 “我的产品”
:)那么 ; 在输入框中仅显示“我的”单词(或数字) “SPACE”(即空格)之后不显示? 像上面这样的输入框可以显示两个或多个单词(以空格分隔)的数据吗?
this is my entire PHP code:
<?php if(empty($_POST['selid']))
{echo "no value selected"; }
else
{
$con = mysql_connect("localhost","root","");
if(mysql_select_db("cdcol", $con))
{
$sql= "SELECT * FROM products where Id = '$_POST[selid]'";
if($result=mysql_query($sql))
{
echo "<form name=\"updaterow\" method=\"post\" action=\"dbtest.php\">";
while($row = mysql_fetch_array($result))
{
echo "Id :<input type=\"text\" name=\"ppId\" value=".$row['Id']." READONLY></input></br>";
echo "Name :<input type=\"text\" name=\"pName\" value=".$row['Name']."></input></br>";
echo "Description :<input type=\"text\" name=\"pDesc\" value=".$row['Description']."></input></br>";
echo "Unit Price :<input type=\"text\" name=\"pUP\" value=".$row['UnitPrice']."></input></br>";
echo "<input type=\"hidden\" name=\"mode\" value=\"Update\"/>";
}
echo "<input type=\"submit\" value=\"Update\">";
echo "</form>";
}
else {echo "Query ERROR";}
}
}
?>
PROBLEM here is, ....if the value i am getting from database using mysql_fetch_array($result)
is like:(say Description is:) "my product"
then;
in input box it shows only "my" the word(or digit)
after "SPACE"(ie blank space) doesn't get displayed?
can input box like above can display the data with two or more words(separated by blank spaces)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将
value
用引号引起来。You need to enclose
value
in quotes.html 解析器无法知道 表示 value=
abc def
。它必须将其解析为两个属性,即具有值abc
的属性value
和不具有值的属性def
。您必须将值括在引号中,例如
您还必须在值内将 " 编码为 " 。否则 html 解析器将再次感到困惑,因为它无法知道 value="abc"def" 中的第二个 " 不是分隔符,而是您可以使用 htmspecialchars() 例如
。
The html parser has no way of knowing that <input value=abc def...> means value=
abc def
. It has to parse it as two attributes, the attributevalue
with the valueabc
and the attributedef
without a value.You have to enclose the value in quotes, e.g. <input value="abc def" ...>
You also have to encode " as " within the value. Otherwise the html parser will get confused again, since it has no way of knowing that the second " in value="abc"def" is not a delimeter but part of the content. You can use htmspecialchars() for this.
e.g.