如何在php下拉列表中获取所选值? [英] How do I get the selected value in a php drop down list?

查看:63
本文介绍了如何在php下拉列表中获取所选值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从SQL获取其值的下拉列表。当用户选择我想将其存储在变量中的值时。目前,当我从下拉列表中选择一个值时,它不会显示该值。



似乎它选择了一个值,我不知道知道为什么吗?



这是我的代码:



I have a drop down list that gets its values from SQL. When a user selects a value I want to store it in a variable. Currently I when I select a value from my drop down list, it doesn't display that value.

It seems that it pr-selects a value and I don't know why?

Here is my code:

<html>
<HEAD>
<link rel="stylesheet" type="text/css" href="mytech.css">
</HEAD>
<body>

<?php

session_start();

if(isset($_SESSION['DeskFusername']))

{

$config = parse_ini_file("noc.ini", true);

  $serverName = $config['server']['SQLserver'];

  $connectionInfo = $config['connectionInfo'];

  $connectionInfo["LoginTimeout"] = 5;

  $conn = sqlsrv_connect($serverName, $connectionInfo);



$tsql = "SELECT userId, EmailAdd
         FROM [Dashboard].[dbo].[EA_t_Master_Users]";









?>
<table id="UserRoles" width="500" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="UserRoles" method="post" action="1.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Create User Login</strong></td>
</tr>

<td>User Name</td>
<td>:</td>
<td>
<select name="UserName" id="UserName">
<?PHP

echo "<option value=\"\" disabled=\"disabled\" selected=\"selected\">Please select a Customer</option>";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
     echo "Error in executing query.<br/>";
     die( print_r( sqlsrv_errors(), true));
}


while ($row=sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC)) {

    if($row['EmailAdd'] == $_POST['UserName'])
    {
        $isSel = " selected";
    }
    else
    {
        $isSel = "";
    }

    echo "<option value=\"".$row['EmailAdd']."\">".$row['EmailAdd']."</option>";

                $UserName = $row['EmailAdd'];

}

//
?>
</select>
</td>
</tr>

<tr>

<td>
<?php



    echo $UserName;



?>
</td>
</tr>


</table>
</td>
</form>
</tr>
</table>
<?PHP

}

else

{

header("location:loginTry1.php");

}

?>

</body>
</html>

推荐答案

_SESSION ['DeskFusername']))

{

_SESSION['DeskFusername'])) {


config = parse_ini_file( noc.ini, true);

config = parse_ini_file("noc.ini", true);


serverName =
serverName =


这篇关于如何在php下拉列表中获取所选值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆