Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PHP中传递所选下拉列表项的值_Php_Html_Selectlist - Fatal编程技术网

在PHP中传递所选下拉列表项的值

在PHP中传递所选下拉列表项的值,php,html,selectlist,Php,Html,Selectlist,我有一个html表单,使用php从表单中间的数据库中获取用户名,我想在用户单击按钮时提交select选项值 文件1: <link href="users_forms.css" rel="stylesheet" type="text/css" /> <div id="rightcolumn"> <form method="post" action="user_remqry.php"> <br /> <l

我有一个html表单,使用php从表单中间的数据库中获取用户名,我想在用户单击按钮时提交select选项值

文件1:

<link href="users_forms.css" rel="stylesheet" type="text/css" />

<div id="rightcolumn">
    <form method="post" action="user_remqry.php">
        <br />
        <legend> Remove Users </legend>
        <fieldset>
            <br />


            <?php
            include'connect.php';
            $q=mysqli_query($con,  "SELECT username FROM users_allow");

            echo "<select name=uname_selected''  ><option value=0>Select a username</option>";
            WHILE($row=mysqli_fetch_array($q))
            {
                echo "<option name='uname_remove' value=$row[username]>".$row[username]."</option>";
            }
            echo "</select>";
            ?>


            <br /> <br /> <br /> <input type="submit" value="Delete User" />
        </fieldset>
    </form>
</div>


删除用户

我只想传递选择列表中所选项的值。

代码中需要更改的内容很少

include 'connect.php'; //please add space
$q=mysqli_query($con,  "SELECT username FROM users_allow");

echo "<select name='uname_selected'>"; //note the position of single quote
echo "<option value='0'>Select a username</option>";
while($row=mysqli_fetch_array($q)){
    echo "<option value='".$row['username']."'>".$row['username']."</option>"; 
} //don't have to put name attribute at the option. Put quotes around $row['username']. Note the single quote surrounding the username
echo "</select>";
包括“connect.php”//请添加空间
$q=mysqli_query($con,“从用户中选择用户名”);
回声“//注意单引号的位置
echo“选择用户名”;
while($row=mysqli\u fetch\u数组($q)){
回显“$row['username']”;
}//不必在选项处放置name属性。在$row['username']周围加引号。注意用户名周围的单引号
回声“;

正如Jerodev提到的,不需要为选项命名。在下一页中,只需调用select的名称。在您的案例中,
$\u POST['uname\u selected']

显示数据库用户名的列表您不需要将name属性添加到select中的每个选项中。您只需命名select,变量
$\u POST[“uname\u selected”]
应包含所选值。感谢帮助,我得到了答案感谢帮助,现在可以使用了,这些单引号和双引号,搜索人为错误时真的很糟糕。很高兴提供帮助。由于人为错误,这是一件很正常的事情。如果有帮助,请考虑将其标记为:-请将我的问题标记为好,因为它是一个真正的问题。
include 'connect.php'; //please add space
$q=mysqli_query($con,  "SELECT username FROM users_allow");

echo "<select name='uname_selected'>"; //note the position of single quote
echo "<option value='0'>Select a username</option>";
while($row=mysqli_fetch_array($q)){
    echo "<option value='".$row['username']."'>".$row['username']."</option>"; 
} //don't have to put name attribute at the option. Put quotes around $row['username']. Note the single quote surrounding the username
echo "</select>";