从组合框返回 php 值


Return php value from ComboBox

我创建了一个带有SQL值的组合框,但我如何知道选择了什么值?这是我的代码,有很多废品,但我的测试:)我链接将所选选项发送到另一个已创建的 php 文件。

    <?php
    require_once('auth.php');
    require_once('config.php');
    require_once('no-cache-headers.php');
    require_once('functions.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nova Mensagem</title>
<link href="Formatacao.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Bem-vindo <?php echo $_SESSION['USERNAME'];?></h1>
<form id="regForm" name="regForm" method="post" action="verificarMensagem.php">
  <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
    <tr>
   <?php
mysql_connect('localhost','comunicat','comunicat');

mysql_select_db('Comunicat');
 $iduser =$_SESSION['SESS_MEMBER_ID'];
$query="Select * from Usuarios where id <> '$iduser'";

$resultado=mysql_query($query);
echo '<select name=”Nome”>';

while($linha=mysql_fetch_array($resultado))
{

echo '<option value="' . $linha['ID'] . '">' . $linha['Nome'] . '</option>';
}
echo '</select>';
?>
    <textarea rows="4" cols="50" name="mensagem" id="mensagem">
</textarea>
      <td>&nbsp;</td>
      <td><input type="submit" name="Submit" value="Enviar" /></td>
    </tr>
  </table>
</form>
</body>
</html>

您可以使用 $_POST[element-of-name] 在 php 中获取 select 元素的值:

<?php
    echo $_POST['Nome'];
?>

这也适用于复选框,收音机等

提交包含"组合框"的表单后,您可以使用以下代码行从组合框中获取所选值:

$val = $_POST['Nome']; // if the form was submitted using post method
$val = $_GET['Nome']; // if the form was submitted using get method

不要再使用 mysql_*,它已被正式弃用。改用 mysqli 或 PDO。