flor Posted May 4, 2007 Share Posted May 4, 2007 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 More sharing options...
taith Posted May 4, 2007 Share Posted May 4, 2007 $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 https://forums.phpfreaks.com/topic/49981-php-select-option-is-not-working/#findComment-245382 Share on other sites More sharing options...
flor Posted May 4, 2007 Author Share Posted May 4, 2007 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 https://forums.phpfreaks.com/topic/49981-php-select-option-is-not-working/#findComment-245393 Share on other sites More sharing options...
Silverado_NL Posted May 4, 2007 Share Posted May 4, 2007 is the ACTION filename right??? are you expecting the $_POST vars??? did you close all the options??? did you close the FORM???? Greetz Silverado Link to comment https://forums.phpfreaks.com/topic/49981-php-select-option-is-not-working/#findComment-245395 Share on other sites More sharing options...
flor Posted May 4, 2007 Author Share Posted May 4, 2007 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 https://forums.phpfreaks.com/topic/49981-php-select-option-is-not-working/#findComment-245401 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.