Jump to content

check dropdown boxes


fr34k2oo4

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.