这是一个从sql表收集数据,回显它们并将其中一个数据作为表单数据发送到另一个页面进行进一步处理的代码
if (isset ( $price_data )) {
$price_query = "SELECT * FROM titem WHERE comment = '$price_data'";
$price_result = mysql_query ( $price_query, $connection );
if (! $price_result) {
echo 'no' . mysql_error ();
}
while ( $price_row = mysql_fetch_array ( $price_result ) ) {
$pr = $price_row['item'];
echo "<h2>" . $price_row['item'] . "</h2><br>";
echo "<input type = checkbox name = selitem value =" . $pr . "/>";
echo $selitem . "<br>";
echo $pr;
echo ' ' . 'Price = ';
if (is_numeric ( $price_row ['price'] )) {
echo $price_row ['price'] . " naira" . "<br>";
} else {
echo $price_row ['price'] . "<br>";
}
}
} else {
echo '';
}
所述变量为$ pr,但每次我在此代码中回显它
<?php
echo $_POST['selitem'];
$sel = $_POST['selitem'];
echo $sel;
$query = "SELECT * FROM titem WHERE item = '$sel'";
$result = mysql_query($query, $connection);
if (isset($result)){echo 'no', mysql_error();}
while ($row = mysql_fetch_array($result))
{echo $row['comment'];}
?>
它只给出了第一个单词而不是完整的东西,当有两个或更多单词时,因此,不允许我用正确的值查询mysql。任何帮助将不胜感激。
答案 0 :(得分:0)
更改此
echo "<input type = checkbox name = selitem value =" . $pr . "/>";
要
echo '<input type="checkbox" name ="selitem" value ="'.$pr.'" />';