从ComboBox返回php值
我创建了一个带有sql值的组合框,但是我如何知道所选的值呢? 这是我的代码,有很多废品,但这是我的测试:) 我链接以将所选选项发送到另一个已创建的php文件从ComboBox返回php值,php,sql,Php,Sql,我创建了一个带有sql值的组合框,但是我如何知道所选的值呢? 这是我的代码,有很多废品,但这是我的测试:) 我链接以将所选选项发送到另一个已创建的php文件 <?php require_once('auth.php'); require_once('config.php'); require_once('no-cache-headers.php'); require_once('functions.php'); ?> <!DOCTYPE
<?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> </td>
<td><input type="submit" name="Submit" value="Enviar" /></td>
</tr>
</table>
</form>
</body>
</html>
诺瓦曼萨吉酒店
本姆文多
您可以使用$\u POST[元素名称]在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
NB
不要再使用mysql了,它已被正式弃用。改用mysqli或PDO。OT:不要在HTML中使用卷曲引号。使用
mysqli\uuu
,还要查看准备好的语句。“
漂亮但致命。是的,但php代码包含id=regForm的HTML表单。因此,使用我发布的代码,您可以在“VerificCarmensage.php”页面上获得combobox值。未定义索引:Nome in/Applications/XAMPP/xamppfiles/htdocs/sir1415/Comunicat/novaMensagem.php第53行,如果表单上有action=“VerificCarmensagement.php”,这意味着表单值应该发布到该页面。这是您可以获取表单值的地方。但是您需要文件“novamensage.php”中的表单值,然后您必须用表单的action属性中的值替换它。。意味着您必须拥有$\u POST['Nome']抱歉,我的NB显示“未定义索引:Nome”$\u POST['Nome']必须在登录文件中(也许最好的方法是遵循一些教程,然后在您了解POST的工作原理后,您将能够正确编写脚本