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

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

is the ACTION filename right???

did you close the FORM????

 

2 x yes

 

are you expecting the $_POST vars???

did you close all the options???

what do you mean by these questions?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.