Jump to content

php select option is not working


flor

Recommended Posts

Hi guys,

 

I'm pretty new at this, and I'm trying to make a very simple script.

It is not doing what I want :(

 

This is my code:

$query="SELECT id, lastname, firstname FROM patient ORDER BY lastname";
$result = mysql_query ($query);
$display_block = "<select name=\"patientnr\">";
while($nt=mysql_fetch_array($result)){
$display_block .= "<option value=\"$nt[id]\">$nt[lastname] $nt[firstname]</option>";
}
$display_block .= "</select>";

 

This part works! hurray!

 

Now the page it directs me to is not working:

 

$query="SELECT id, lastname, firstname FROM patient WHERE id = '{$_POST['patientnr']}'";

$display_block = "<p>$id</p><p>$lastname</p><p>$firstname</p>";

 

This always returns an empty result.

Can anyone see why?

 

Link to comment
https://forums.phpfreaks.com/topic/49981-php-select-option-is-not-working/
Share on other sites

$result=mysql_query("SELECT id, lastname, firstname FROM patient ORDER BY lastname") or die(mysql_error());

$display_block="<select name=\"patientnr\">";

while($nt=mysql_fetch_assoc($result)){

$display_block.="<option value=\"$nt[id]\">$nt[lastname] $nt[firstname]</option>";

}

$display_block.="</select>";

Hi,

 

The first part actually works, it returns this html:

<form id="selectpatient" name="selectpatient" method="post" action="getpatient.php">

  <p><select id="patientnr" name="patientnr"><option value="1">patient pete</option><option value="2">patient paul</option></select></p>
  <p>
    <input type="submit" name="Submit" value="Submit" />

 

But if I click submit, I get an empty result, where I think I should be getting the details of patient with option value=1 or 2

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.