//I extracted data from database like
<form action="print.php" method="post">
<?php include('connection.php') ?>
<?php
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT * FROM nokia");
$num = mysql_numrows($sql);
?>
<?php
$i=0;
while ($i < $num) {
$f6=mysql_result($sql,$i,"item_name");
<input type="checkbox" name="list[]" value="<?php echo "$f6";?>" /><?php echo "$f6","<br>"; ?>//display result in htmlpage
<?php
$i++;
$d=$f6;
}
?>
<input type="submit" value="submit"/>
</form>
print.php
//after submitting in php page
<?php include('connection.php') ?>
<?php
if(isset($_POST['submit']))
{
if(!empty($_POST['list']))//name of checkbox in html
{
foreach($_POST['list'] as $selected){
echo $selected."</br>";
}
}
}
?>
//display nothing in php...how I solve this problem我想要显示复选框的内容从html格式到php页面。我从database.problem中提取的复选框内容是我如何在php页面中显示内容,选择多个复选框。
发布于 2016-02-01 17:48:08
首先,在代码中添加error_reporting:
ini_set('error_reporting', E_ALL);
error_reporting(E_ALL);在您的HTML/PHP组合中有几个问题:
问题:
<input type="checkbox" ..。name="submit" in按钮添加名称。修改代码:
<?php
$i=0;
while ($i < $num) {
$f6=mysql_result($sql,$i,"item_name");
?>
<input type="checkbox" name="list[]" value="<?php echo $f6;?>" /><?php echo $f6; ?><br/>
<?php
$i++;
$d = $f6;
}
?>旁注:
error_reporting的建议仅用于开发和试运行,不用于生产。
请使用mysqli_*或PDO,因为mysql_*已弃用,在PHP7中不可用。
发布于 2016-02-01 17:41:48
<?php echo "$f6","<br>"; ?>错误的连接
<?php echo "$f6"."<br>"; ?>使用这个
发布于 2016-02-01 17:47:36
你的代码应该是:-
<?php
// This line should be first.
// You have missed semicolon here.
include('connection.php');
// Query member data from the database and ready it for display
$sql = mysql_query("SELECT * FROM nokia");
$num = mysql_numrows($sql);
?>
<form action="print.php" method="post">
<?php
$i=0;
while ($i < $num) {
$f6=mysql_result($sql,$i,"item_name");
?>
<!-- You should write below line as -->
<input type="checkbox" name="list[]" value="<?php echo $f6;?>" /><?php echo $f6; ?> </br>
<?php
$i++;
$d=$f6;
}
?>
<input type="submit" value="submit"/>
</form> https://stackoverflow.com/questions/35127168
复制相似问题