RaJiska Posted November 1, 2013 Share Posted November 1, 2013 Hello, I have a drop down menu, and I wish to know how to get the value selected in the drop down (made with HTML & CSS) into a PHP variable. Here is how it looks like: <html> <body> <form name="myform" action="" method=""> <div align="center"> <select name="mydropdown"> <option value="1h">1 Hour</option> <option value="3h">3 Hours</option> <option value="12h">12 Hours</option> <option value="1d">1 Day</option> <option value="3d">3 Days</option> <option value="1w">1 Week</option> <option value="2w">2 Weeks</option> <option value="3w">3 Weeks</option> <option value="1m">1 Month</option> </select> </div> </form> </body> </html> Then it should be get when this PHP button is pressed: echo('<input type="submit" name="test" value="Hello My Name is Bob"/>'); Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/283511-get-drop-down-value-of-html-in-php/ Share on other sites More sharing options...
Ch0cu3r Posted November 1, 2013 Share Posted November 1, 2013 (edited) As you haven't set the forms submit mehtod (method="") <form name="myform" action="" method=""> and you have named your drop down menu as mydropdown <select name="mydropdown"> When the form has been submitted, then you'll get the selected value using $_GET['mydropdown']. If you set the forms submit method to post (method="post") you'd use $_POST['mydropdown'] Edited November 1, 2013 by Ch0cu3r Quote Link to comment https://forums.phpfreaks.com/topic/283511-get-drop-down-value-of-html-in-php/#findComment-1456514 Share on other sites More sharing options...
RaJiska Posted November 1, 2013 Author Share Posted November 1, 2013 (edited) Yep, thanks, it worked with $_POST. Alos, I might have to ask another question, it's here: $test1 = 1; $test2 = 1; if ($ip == $test1 || $test2) { ?> <br><input type="submit" value="Click test" /> <?php } echo "IP: $ip"; ?> The problem is with: if ($ip == $test1 || $test2) (that is not normal since my IP is not '1' or '1'), I can see the button, but with: if ($ip == $test1) I can (that should be normal since my IP is not 1).ThankS. Edited November 1, 2013 by RaJiska Quote Link to comment https://forums.phpfreaks.com/topic/283511-get-drop-down-value-of-html-in-php/#findComment-1456550 Share on other sites More sharing options...
slyte33 Posted November 1, 2013 Share Posted November 1, 2013 Yep, thanks, it worked with $_POST. Alos, I might have to ask another question, it's here: $test1 = 1; $test2 = 1; if ($ip == $test1 || $test2) { ?> <br><input type="submit" value="Click test" /> <?php } echo "IP: $ip"; ?> The problem is with: if ($ip == $test1 || $test2) (that is not normal since my IP is not '1' or '1'), I can see the button, but with: if ($ip == $test1) I can (that should be normal since my IP is not 1). ThankS. Try this if ($ip == $test1 || $ip == $test2) Quote Link to comment https://forums.phpfreaks.com/topic/283511-get-drop-down-value-of-html-in-php/#findComment-1456552 Share on other sites More sharing options...
RaJiska Posted November 1, 2013 Author Share Posted November 1, 2013 Thanks a lot, it worked, how can it be possible ? I earlier tested this on another page, and it worked perfectly. Quote Link to comment https://forums.phpfreaks.com/topic/283511-get-drop-down-value-of-html-in-php/#findComment-1456554 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.