desjardins2010 Posted December 27, 2010 Share Posted December 27, 2010 hey guys I know this is html but I'm using the php $_POST to grab the information the user chooses, i can't figure out though how to grab the info i'm looking for in this select option form if they choose PasswordCracker v3.0 what is it i'm looking to set my $_post['']; to? <FORM action="buy.php" method="POST"> <select name="passwordcrakers"> <option value="v2.0">PasswordCracker V2.0</option> <option value="v3.0">PasswordCracker V3.0</option> <option value="v4.0">PasswordCracker V4.0</option> <option value="v5.0">PasswordCracker V5.0</option> <option value="v6.0">PasswordCracker V6.0</option> <option value="v7.0">PasswordCracker V7.0</option> <option value="v8.0">PasswordCracker V8.0</option> <option value="v9.0">PasswordCracker V9.0</option> <option value="v10">PasswordCracker V10</option> </select><br /> <input type="submit" value="Buy" name="submit" /> </FORM> Link to comment https://forums.phpfreaks.com/topic/222742-using-_post/ Share on other sites More sharing options...
freelance84 Posted December 27, 2010 Share Posted December 27, 2010 The value you gave it: v3.0 Link to comment https://forums.phpfreaks.com/topic/222742-using-_post/#findComment-1151818 Share on other sites More sharing options...
desjardins2010 Posted December 27, 2010 Author Share Posted December 27, 2010 so something like $submit = $_POST['submit']; if ($submit) { $v2 = $_POST['v2.0']; $v3 = $_POST['v3.0']; } echo $v2; //should echo "PasswordCrackerv2.0" Link to comment https://forums.phpfreaks.com/topic/222742-using-_post/#findComment-1151823 Share on other sites More sharing options...
freelance84 Posted December 27, 2010 Share Posted December 27, 2010 Yup, but you could also put the $_POST['submit'] inside the if statement to cut down on lines. Also this tutorial was pretty helpful to me... http://www.phpfreaks.com/tutorial/php-security for the security issues you need to be concerned about Link to comment https://forums.phpfreaks.com/topic/222742-using-_post/#findComment-1151827 Share on other sites More sharing options...
the182guy Posted December 27, 2010 Share Posted December 27, 2010 No, $_POST['v3.0']; is wrong, there is no field called v3.0 is there, the field is called passwordcrackers and the value would be the v3.0 if that was selected. it should be $version = $_POST['passwordcrackers']; // $version would be v2.0 or v3.0 etc, depending on which option was selected from the dropdown if($version == 'v3.0') { // user selected version 3.0 } Link to comment https://forums.phpfreaks.com/topic/222742-using-_post/#findComment-1151828 Share on other sites More sharing options...
freelance84 Posted December 27, 2010 Share Posted December 27, 2010 oh blimey sorry desjardins2010, really wasn't thinking straight there. Think i was assuming you were looking to do something if the user selected "v3.0": if(isset($_POST['submit'])) { if($_POST['passwordcrackers'] == 'v3.0') { .... do or set set something } elseif(...something else) { } } ... my bad too much xmas food Link to comment https://forums.phpfreaks.com/topic/222742-using-_post/#findComment-1151845 Share on other sites More sharing options...
desjardins2010 Posted December 27, 2010 Author Share Posted December 27, 2010 Thanks plenty guys always there to save me Link to comment https://forums.phpfreaks.com/topic/222742-using-_post/#findComment-1151870 Share on other sites More sharing options...
the182guy Posted December 27, 2010 Share Posted December 27, 2010 Don't use if(isset($_POST['submit'])) to test if a form has been submitted. Use: if($_SERVER['REQUEST_METHOD'] == 'POST') { // form is submitted } Using the isset way will mean that if the user presses the enter key to submit the form with internet explorer, your code will not pickup the fact that the form has been submitted. Link to comment https://forums.phpfreaks.com/topic/222742-using-_post/#findComment-1151893 Share on other sites More sharing options...
freelance84 Posted December 27, 2010 Share Posted December 27, 2010 really? ah crap, i've got some work to do! Does that even apply if the submit button is named something else, eg: <input type="submit" name="save_change" value="Save Changes"/> Link to comment https://forums.phpfreaks.com/topic/222742-using-_post/#findComment-1151921 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.