简体   繁体   English

获取表单中选择框的值

[英]get value of the select box in a form

im tryin to get the selected value from select box i used this to get the result 我尝试从选择框中获取选定的值,我用它来获取结果

$receiver=$_POST['receiver'];

but i keep getting the result 0 anyone ? 但我一直得到0个结果吗?

<form method="post" action="new.php?send"> 
<label for="select">

<select name="receiver" value="Select" size="1">

<?php
$sql = "SELECT fullname FROM users"; 

    $result = mysql_query($sql) or die (mysql_error()); 

    while ($row = mysql_fetch_array($result))

    { 
            $id=$row["id"]; 
            $name=$row["fullname"]; 
            $options .= '<option name="selected" value="'.$id.'">'.$name.'</option>';
    }

echo $options; ?>
</option>

</select>
<input id="send" type="submit" name="Submit" value="Submit">
</form>

Your SQL is wrong. 您的SQL错误。 You are trying to print the ID, but you are not selecting it. 您正在尝试打印ID,但未选择它。 Also, there is an unneeded </option> right before the closing tag of your select - that might cause problems too. 另外,在select的结束标记之前没有必要的</option> ,这也可能会引起问题。

select id,fullname from users 从用户中选择ID,全名

so that you can fetch id and in last you are writing .no need o 这样您就可以获取id并最后编写。不需要o

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM