我的页面中有两个复选框。两个复选框的数据都是从数据库驱动的。不,我试图获取每个复选框的值,但它显示在上面。这是我的剧本
<?php include('conn.php'); ?>
<!doctype html>
<html><head>
<meta charset="utf-8">
<title>New Page</title>
<style type="text/css">
#div{
height:500px; width:150px; overflow:auto;
border:thin;
float:left;
}
#div2{
height:auto;
width:150px;
overflow:auto;
border:thin;
}
</style>
</head>
<body>
<form name="" action="2nd.php" method="post">
<div style="border:1; border-color:#006;">
<?php
$sql=$connection->query("SELECT * FROM provinces");
echo "<div id=\"div\">";
while($result=$sql->fetch_assoc()){
//echo "<input type=\"checkbox\" name=\""; echo $result['name']; echo" \" "; echo $result['name']; echo" />";
echo "
<input type=\"checkbox\" name=\"check[]\" value\""; echo $result['name']; echo" \" />";
echo $result['name'];
echo "<br/>";
}
echo "</div>";
?>
<?php
$sql=$connection->query("SELECT * FROM commodities");
echo "<div id=\"div2\">";
while($result=$sql->fetch_assoc()){
//echo "<input type=\"checkbox\" name=\""; echo $result['name']; echo" \" "; echo $result['name']; echo" />";
echo "
<input type=\"checkbox\" name=\"check[]\" value\""; echo $result['name']; echo" \" />";
echo $result['name'];
echo "<br/>";
}
echo "</div>";
?>
<input type="submit" name="save"/>
</div>
</form>
</body></html>
此代码处理第1页的内容,但显示在上面。
<?php
$check=$_REQUEST['check'];
foreach($check as $instrument)
{
echo $instrument.'<br>';
}
?>
答案 0 :(得分:1)
=
属性的名称与value
之间需要"data"
个符号。
validator是一个有用的工具。
答案 1 :(得分:0)
请注意,如果你没有提供value =“”那么在这种情况下复选框它会显示'on'
将语法值\“”更正为value = \“\”
答案 2 :(得分:0)
谢谢大家的帮助。这是我完整的工作代码。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>New Page</title>
<style type="text/css">
#div{
height:500px;
width:150px;
overflow:auto;
border:thin;
float:left;
}
#div2{
height:auto;
width:150px;
overflow:auto;
border:thin;
}
</style>
</head>
<body>
<form name="" action="2nd.php" method="post">
<div style="border:1; border-color:#006;">
<?php
$sql=$connection->query("SELECT * FROM provinces");
echo "<div id=\"div\">";
while($result=$sql->fetch_assoc()){
//echo "<input type=\"checkbox\" name=\""; echo $result['name']; echo" \" "; echo $result['name']; echo" />";
echo "
<input type=\"checkbox\" name=\"check[]\" value=\""; echo $result['name']; echo" \" />";
echo $result['name'];
echo "<br/>";
}
echo "</div>";
?>
<?php
$sql=$connection->query("SELECT * FROM commodities");
echo "<div id=\"div2\">";
while($result=$sql->fetch_assoc()){
echo "<input type=\"checkbox\" name=\"check[]\" value=\""; echo $result['name']; echo" \" />";
echo $result['name'];
echo "<br/>";
}
echo "</div>";
?>
<input type="submit" name="save"/>
</div>
</form>
</body>
</html>
处理表单的第二页代码。
<?php
$check=$_REQUEST['check'];
foreach($check as $instrument)
{
echo $instrument.'<br>';
}
?>