fr34k2oo4 Posted March 23, 2009 Share Posted March 23, 2009 I'm working on a webpage where you can login and by a particular choice it sends you to another page. this is the box in HTML: <form method='post' action='<?php echo $_SERVER['PHP_SELF']; ?>'> <select name="option[]" size="1"> <option value="1">goto page 1</option> <option value="2">goto page 2</option> <option value="3">goto page 3</option> </select> </form> this code is correct since it's also used for logging in users. the tricky part for me came when I wanted to check the choice of the user and direct the user to that page when the login button is clicked. The code for checking the listbox looks like this: if($_POST['option'] == 1) { $cfg['loggedIn'] = "page1.php"; } elseif ($_POST['option'] == 2) { $cfg['loggedIn'] = "page2.php"; } elseif($_POST['option'] == 3) { $cfg['loggedIn'] = "page3.php"; } // login was successfull. redirect to the chosen page location header("Location: ".$cfg['loggedIn']); now the code above doesn't work, so that is why I started this topic. anyone any suggestions? Thanks in forward Greets Link to comment https://forums.phpfreaks.com/topic/150696-check-dropdown-boxes/ Share on other sites More sharing options...
kickstart Posted March 23, 2009 Share Posted March 23, 2009 Hi It is because of the square brackets. $_POST['option'] is in itself an array. Either remove the square brackets from the select or specify $_POST['option'][0]; All the best Keith Link to comment https://forums.phpfreaks.com/topic/150696-check-dropdown-boxes/#findComment-791647 Share on other sites More sharing options...
fr34k2oo4 Posted March 23, 2009 Author Share Posted March 23, 2009 removing the brackets at the select worked, the other option didn't. So that might help you aswell Thanks Link to comment https://forums.phpfreaks.com/topic/150696-check-dropdown-boxes/#findComment-791651 Share on other sites More sharing options...
kickstart Posted March 23, 2009 Share Posted March 23, 2009 removing the brackets at the select worked, the other option didn't. So that might help you aswell Should work (and does when I have a quick play). All the best Keith Link to comment https://forums.phpfreaks.com/topic/150696-check-dropdown-boxes/#findComment-791654 Share on other sites More sharing options...
FaT3oYCG Posted March 23, 2009 Share Posted March 23, 2009 removing the brackets at the select worked, the other option didn't. So that might help you aswell Should work (and does when I have a quick play). All the best Keith yeah id does usually work both ways, you might just want to check up on php arrays over at w3schhols.com for a better understanding p.s. keith please watch what you are saying, read what you just said back to yourself lol Link to comment https://forums.phpfreaks.com/topic/150696-check-dropdown-boxes/#findComment-791663 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.