robinhood Posted September 12, 2007 Share Posted September 12, 2007 Can any 1 help me on my mistakes.I suppose i had declare the :".$_POST['drop1']; wrongly .i am trying to display the selected items form the drop list using post method but it failed. //populating rank/name from admin table to drop down list $query="SELECT name FROM admin where timecounter='1'"; /*order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query); echo "<select name='drop1'Select Name>"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo "<option value=$nt[id]>$nt[name]</option>"; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?> </p> <p> <input type="submit" name="Submit" value="Submit" > </p> </form> </body> <?php echo "Name is:".$_POST['drop1']; ?> <p></p> <p></p> <?php echo "Product Description:".$_POST['jobdescription']; ?> </html> Link to comment https://forums.phpfreaks.com/topic/68978-unable-to-post-results-of-selected-droplist-item-using-database/ Share on other sites More sharing options...
gerkintrigg Posted September 12, 2007 Share Posted September 12, 2007 put the </body> tag at the bottom and seperate the echo statement from the rest of the code with : if ($submit){ Link to comment https://forums.phpfreaks.com/topic/68978-unable-to-post-results-of-selected-droplist-item-using-database/#findComment-346742 Share on other sites More sharing options...
robinhood Posted September 12, 2007 Author Share Posted September 12, 2007 i am using 2 post methods but only of drop list was not displaying output. how to go about using if ($submit){ Link to comment https://forums.phpfreaks.com/topic/68978-unable-to-post-results-of-selected-droplist-item-using-database/#findComment-346753 Share on other sites More sharing options...
GingerRobot Posted September 12, 2007 Share Posted September 12, 2007 Something like: <?php $query="SELECT name FROM admin where timecounter='1'"; /*order by clause to the sql statement if the names are to be displayed in alphabetical order */ $result = mysql_query ($query) or die(mysql_error()); echo "<select name='drop1'"; // printing the list box select command while($nt=mysql_fetch_array($result)){//Array or records stored in $nt echo '<option value='.$nt['id'].'>'.$nt['name'].'</option>'; /* Option values are added by looping through the array */ } echo "</select>";// Closing of list box ?> </p> <p> <input type="submit" name="Submit" value="Submit" > </p> </form> <?php if(isset($POST('Submit'))){ echo 'Name is: '.$_POST['drop1'].'<br />Product Description: '.$_POST['jobdescription']; } </body> </html> Edit: You do however realise that you will be getting the ID from the drop down box and not the name? Since you set the value of each option to the id rather than the name, that is what you will receive. This is probably what you want if you are doing anything with a database, but not if you want to display the name. Link to comment https://forums.phpfreaks.com/topic/68978-unable-to-post-results-of-selected-droplist-item-using-database/#findComment-346786 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.