嗯,我真的没有得到它,但我的代码以某种方式返回一个空字符串? 这是代码:
<form id="form1" name="form1" method="post" action="">
<p>
</p>
<p>
<select name="lbox" id="listbox">
<?php
$sqlString = "SELECT * FROM admintbl";
$con = mysql_connect("localhost","root","");
mysql_select_db("dbmain", $con);
$dat = mysql_query($sqlString);
$user = "";
while ($row_i = mysql_fetch_assoc($dat)) {
if ($user !== $row_i['user']) {
$user = "";
}
if ($user == "") {
$user = $row_i['user'];
?>
<option value=<?php $user ?>><?php echo $user ?></option>";
<?php
}
?>
<?php }
echo mysql_error();
mysql_close($con);
?>
</select>
<input type="submit" id="submit" name="submit"/>
</p>
</form>
这里是我试图从列表框中获取值但是为空的。
<?php
if (isset($_POST['submit'])) {
$check = $_POST['lbox'];
echo "<script> alert('$check')</script>";
if ($check == "mac") {
echo "<script> alert('this message')</script>";
}
}
?>
有关做什么或我错在哪里的任何想法?我真的不明白为什么。 &#34; mac&#34;被设置为列表框中选项中的值之一。谢谢,更多的力量给你们!
答案 0 :(得分:0)
试试此代码
<form id="form1" name="form1" method="post" action="">
<p>
</p>
<p>
<select name="lbox" id="listbox">
<?php
$sqlString = "SELECT * FROM admintbl";
$con = mysql_connect("localhost","root","");
mysql_select_db("dbmain", $con);
$dat = mysql_query($sqlString);
$user = "";
while ($row_i = mysql_fetch_assoc($dat)) {
if ($user !== $row_i['user']) {
$user = "";
}
if ($user == "") {
$user = $row_i['user'];
?>
<option value=<?php echo $user; ?>><?php echo $user; ?></option>";
<?php
}
?>
<?php }
echo mysql_error();
mysql_close($con);
?>
</select>
<input type="submit" id="submit" name="submit"/>
</p>
</form>