tags:

views:

61

answers:

3
function getLink($sa){
    if($sa=='1'){
        $sa = 'qp_bbl';
    } else {
        $sa = 'qp_sbl';
    } 
    return $sa;
}

if(!$_POST['action']){
    header ("Location: index.php"); 
}else{

$sa = $_POST['select'];

$sa = getLink($sa); 


$link = connect(HOST, USER, PASSWORD, $sa);

(....)
}

This is driving me crazy. Select can be '1' or '2'. If i hard code $sa = '1' or '2' it all works great but if get set it from $_POST['select'] it's a no go. I don't really understand...

+1  A: 

You could try examining the contents of $_POST using print_r($_POST) to make sure that $_POST['select'] is getting passed.

You should not be making a database connection based on $_POST data, though. This is not very secure. If you want to conditionally select a database based on $_POST, try something like this:

switch($_POST['select']) {

  case '1':  $db = '1';  break;
  default:   $db = '2';

}

That way you are sure that you are selecting a valid db.

jonstjohn
+2  A: 

With this solution you need to post "sa" on every page request, otherwise it will always fall back to "qp_sbl" for any other request, since you don't seem to store which database you want to use during the session.

jishi
A: 

To continue jonstjohn's comment about print_r... it would also pay for us to see the initial form that is meant to be posting to this script, in case there's a problem there.

It may also help to just store the select value in the session when it is posted and then just use the value from the session until it changes.

Narcissus