Mufleeh Posted July 12, 2011 Share Posted July 12, 2011 Hi all, I have used a dropdown menu inside the <form> tag. There are list of zones and one will be selected. I would like to whether I can use PHP inside the <form></form> as I have used below and how to get the id of the selected one from the drop down men. Below is my code and it doesn't work as I expect, please advice. <form method="post" id="graphDraw" action="<?php echo $_SERVER['SCRIPT_NAME']?>"> <?php echo "<select name=\"".'zone_id'."_zone_".$zoneNo."\" style=\"width: 175px\">"; foreach($this->allZones as $zone) { echo "<option"; echo " value='$zone[zone_id]' "; echo ">"; echo $zone['zone_id'].": ".$zone['zone_name']; echo "</option>"; } echo"</select>"; ?> <input type="submit" value="Generate Graph"/> </form> Once the button is clicked I need to get the id (zone_id) of the selected zone in the drop down menu and send it to a query. Regards, Mufleeh Quote Link to comment https://forums.phpfreaks.com/topic/241785-php-form/ Share on other sites More sharing options...
cyberRobot Posted July 12, 2011 Share Posted July 12, 2011 I'm not sure what $zoneNo contains, but let say you select tag looks like this: echo "<select name='zone_id' style=\"width: 175px\">"; In the code that processes the form submission, the zone_id can be retrieved with the following variable: $_POST['zone_id'] Quote Link to comment https://forums.phpfreaks.com/topic/241785-php-form/#findComment-1241756 Share on other sites More sharing options...
Mufleeh Posted July 12, 2011 Author Share Posted July 12, 2011 I'm not sure what $zoneNo contains, but let say you select tag looks like this: echo "<select name='zone_id' style=\"width: 175px\">"; In the code that processes the form submission, the zone_id can be retrieved with the following variable: $_POST['zone_id'] Hi cyberRobot, Thanks for your response! I made the it but there are problems in the queries if you could help me it would be really appriciated, http://www.phpfreaks.com/forums/index.php?topic=338495.0 Regards, Mufleeh Quote Link to comment https://forums.phpfreaks.com/topic/241785-php-form/#findComment-1241764 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.