Php 基于单选按钮值从数据库检索数据
我对php和mysql很陌生,所以如果我完全错了,请原谅我。我正在制作一个打印平衡应用程序,下面的代码是其中的一部分Php 基于单选按钮值从数据库检索数据,php,mysql,Php,Mysql,我对php和mysql很陌生,所以如果我完全错了,请原谅我。我正在制作一个打印平衡应用程序,下面的代码是其中的一部分 $command="SELECT itemname FROM items"; $results = mysql_query($command); while($row = mysql_fetch_assoc($results)) { foreach ($row as $key => $value) { print "<input typ
$command="SELECT itemname FROM items";
$results = mysql_query($command);
while($row = mysql_fetch_assoc($results))
{
foreach ($row as $key => $value) {
print "<input type='radio' name='itemtype' value='$value'>".$value."</input><br />";
}
}
确实是这样
SELECT itemprice FROM items WHERE itemname = $_POST['itemtype']
假设itemprice是价格的实际列。然而,这样做会使您的代码容易受到mysql注入的攻击。所以,在你开始思考之前,先考虑一下阅读。你为什么不试一下?是的,我有处理MySQL注入所需要的东西。无论如何,错误“Parse error:syntax error,unexpected”(T_ENCAPSED_和_空格),预期标识符(T_字符串)或变量(T_变量)或数字(T_NUM_字符串)将与代码一起出现。不过,我能够在线查找解决方案,并能够修复它。非常感谢你的回复。我知道我离得越来越近了,但我已经厌倦了绕圈子试图弄明白这一点。非常感谢指导^^
SELECT itemprice FROM items WHERE itemname = $_POST['itemtype']