How to get and send to a php file a combobox selection

Asked

Viewed 157 times

1

I need to know how to reach the selected value on combobox when you press the commit button and how to call that value in the new file .php:

I know there are similar examples already here, but note that my combobox is dynamic not fixed, and also attention that I have .html, afterward .phpand again .html, It’s messing me up.

I have the following code:

<?php
require_once('auth.php');
require_once('config.php');
require_once('no-cache-headers.php');
require_once('functions.php');
?>

<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">

<?php

mysql_connect('localhost','comunicat','comunicat');

mysql_select_db('Comunicat');

$iduser =$_SESSION['SESS_MEMBER_ID'];

$query="Select * from Usuarios where id <> '$iduser'";

$_SESSION['IdUser'] = $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><input type="submit" name="Submit" value="Enviar" /></td>
    </tr>
  </table>
</form>

</body>
</html>

------------ check.php -----------------

$link = new mysqli("localhost", "comunicat", "comunicat", "Comunicat");

if (!$link) {
    die('Could not connect: ' . mysql_error());
}
 $Id_User = $_SESSION['IdUser'];

 $nome = $_POST['Nome'];

if ($_SERVER['REQUEST_METHOD'] == 'POST') 
....

  • Mine is slightly different, and it is this difference that makes the difference, in this example is only php, in my have php and html

  • Besides, the values of the example are only 2 and fixed, mine are dynamic, comes from BD.

  • Exactly, but I put $var = $_POST['Name']; and tell me that the variable does not exist, so I must be putting something wrong.

  • Well, I put in a comment and deleted it, because to me duplicates should contain accepted answers. Second, has ctz that the name should be put in the string format? The related question is not like this.

  • Those differences you said don’t make a difference. $var = $_POST['Nome']; must give the chosen option.

  • 1

    Hello, as I mentioned above the "$var = $_POST['Name'];" does not work, says that the variable does not exist.

  • @Sa try to change the name of name="Nome" for name=Nome. I don’t work with php, but the related question is in this format.

  • @Sapires put the file code verificarMensagem.php. The form code is apparently correct.

  • @Gustavocinque The correct is to delimit the attributes, for example the name, quotation marks. And that’s HTML, not PHP =)

  • 1

    You could post the code where you are trying to recover the value of combobox? the combobox is being populated correct with data from BD?

  • Try to explain better what the problem is. You’re doing something wrong, the way to pick variables from a form is the same. $var = $_POST['oNamedaVariavel'];. And it doesn’t matter if you have HTML in the middle or if the information comes from the bank.

  • I already added the checkMensagem.php , the combobox is fed correctly and values are listed

Show 7 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.