Ask about general coding issues or problems here.
Moderators: macek, egami, gesf
by paulotorres » Sun Dec 23, 2012 8:16 am
<h1>Consultar Paciente</h1>
<?php
if(empty($_POST)=== true) {
$sql = "SELECT `nome_paciente` FROM `pacientes`";
$resultado = mysql_query($sql);
print " Nome do Paciente:";
print "<select name='nome'>";
while ($row= mysql_fetch_array($resultado)){
print "<option value='". $row['nome_paciente']. "'>" .$row['nome_paciente']."</option>";
}
echo "</select>";
}
else
{
while ($row= mysql_fetch_array($resultado)){
print "<option value='". $row['nome_paciente']. "'>" .$row['nome_paciente']."</option>";
}
print "</select>";
}
?>
<form action="" method="post">
<ul>
<li> <input type="submit" value="Seleccionar" /></li>
<li><br />
</ul>
</form>
<?php
print_r( $_POST['nome']);
?>
The command print_r($_POST['nome']); doesn´t print anything. Why is that. It should print the value selected but i get nothing.
i´d like some help please...
Best Regards,
Paulo Torres
-
paulotorres
- New php-forum User

-
- Posts: 1
- Joined: Sun Dec 23, 2012 7:55 am
by simplypixie » Thu Dec 27, 2012 12:57 am
Because your form element being generated by your PHP isn't inside your form.
- Code: Select all
<h1>Consultar Paciente</h1>
<form action="" method="post">
<?php
if(!isset($_POST)) {
$sql = "SELECT `nome_paciente` FROM `pacientes`";
$resultado = mysql_query($sql);
echo " Nome do Paciente:";
echo "<select name='nome'>";
while ($row= mysql_fetch_array($resultado)){
echo "<option value='". $row['nome_paciente']. "'>" .$row['nome_paciente']."</option>";
}
echo "</select>";
}
else
{
while ($row= mysql_fetch_array($resultado)){
echo "<option value='". $row['nome_paciente']. "'>" .$row['nome_paciente']."</option>";
}
echo "</select>";
}
?>
<ul>
<li> <input type="submit" value="Seleccionar" /></li>
<li><br />
</ul>
</form>
<?php
print_r( $_POST['nome']);
?>
-

simplypixie
- php-forum Active User

-
- Posts: 289
- Joined: Sun Dec 11, 2011 12:51 am
- Location: Shrewsbury, Shropshire
-
Return to PHP coding => General
Who is online
Users browsing this forum: No registered users and 2 guests