Passing 2 variables to Header location URL

Discussion in 'PHP' started by KangBroke, May 26, 2012.

  1. #1
    any got any ideas why this passes the second variable blank?????



    header('location: admin_home.php?tournament_id='.urlencode($tournament_id).'&color='.urlencode($color));
    		 exit;
    PHP:
    first variable passes even if I switch the order. Meaning color=X shows if i make it first.
     
    Solved! View solution.
    KangBroke, May 26, 2012 IP
  2. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #2
    Try:
    
    $url = 'admin_home.php?tournament_id=' . urlencode($tournament_id) . '&color=' . urlencode($color);
    header("Location: {$url}");
    exit;
    
    PHP:
     
    kbduvall, May 26, 2012 IP
  3. KangBroke

    KangBroke Notable Member

    Messages:
    1,026
    Likes Received:
    59
    Best Answers:
    4
    Trophy Points:
    265
    #3
    this may work however, $color isnt being stored at all i just realized
     
    KangBroke, May 26, 2012 IP
  4. KangBroke

    KangBroke Notable Member

    Messages:
    1,026
    Likes Received:
    59
    Best Answers:
    4
    Trophy Points:
    265
    #4
    <?php
    	include('db_config.php');
    	
    	$username = isset($_REQUEST['txtUser'])?$_REQUEST['txtUser']:'';
    	$password = isset($_REQUEST['txtPass'])?$_REQUEST['txtPass']:'';
    	$salt = 's+(_a*';
            $password = md5($password.$salt);
            $password = substr($password, 0, 10);
    	$tournament_id=$_POST['tournament_id'];
            $url = 'admin_home.php?tournament_id=' . $admin_id . '&color=' . $color;
            $sql1 = "SELECT * FROM `tournament` where `color` = `$color` and `tournament_id` = `$tournament_id`";
    	$query1 = mysql_query($sql1);
    
    
    	$sql = "SELECT * FROM `admin` where username='$username' and password='$password'";
    	$query = mysql_query($sql);
    	$row = mysql_fetch_array($query);
    	$adminid=$row['admin_id'];
    
    	if(($adminid>0))
    	{
    		$_SESSION['logged']=true;
    		$_SESSION['admin_id']=$username;
    		$_SESSION['id']=$adminid;
    
    header("Location: {$url}");
    		 exit;
    	}
    		header('location:index.php?msg=Invalid admin login details');	
    		
    	
    	
    ?>
    
    
    
    
    
    
    
    
    
    PHP:




    If you really think you can help me, I cant figure out why its not storing $color. All the DB info is correct and does exist. the color pulls from tournament. row is called 'color'
     
    KangBroke, May 26, 2012 IP
  5. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #5
    I'm not seeing where you've defined $color. I see you define $tournament_id from $_POST['tournament_id']. Is the value for $color in the $_POST? $color = $_POST['color']; maybe?
     
    kbduvall, May 26, 2012 IP
  6. KangBroke

    KangBroke Notable Member

    Messages:
    1,026
    Likes Received:
    59
    Best Answers:
    4
    Trophy Points:
    265
    #6
    <?php
    	include('db_config.php');
    	
    	$username = isset($_REQUEST['txtUser'])?$_REQUEST['txtUser']:'';
    	$password = isset($_REQUEST['txtPass'])?$_REQUEST['txtPass']:'';
    	$salt = 's+(_a*';
            $password = md5($password.$salt);
            $password = substr($password, 0, 10);
    	
    $tournament_id=$_POST['tournament_id'];
    
    
      	$color=$_POST['color']; 
    	$sql = "SELECT * FROM `admin` where username='$username' and password='$password'";
    	$query = mysql_query($sql);
    	$row = mysql_fetch_array($query);
    	$adminid=$row['admin_id'];
    
    	if(($adminid>0))
    	{
    		$_SESSION['logged']=true;
    		$_SESSION['admin_id']=$username;
    		$_SESSION['id']=$adminid;
    		header('location: http://www..com/Admin/admin_home.php?tournament_id='.urlencode($tournament_id).'&color='.urlencode($tournament_id));
    		 exit;
    	}
    		header('location:index.php?msg=Invalid admin login details');	
    		
    	
    	
    ?>
    
    
    
    
    
    
    
    
    PHP:

    does not pass a second value
    url comes up blank for second value
     
    KangBroke, May 26, 2012 IP
  7. kbduvall

    kbduvall Peon

    Messages:
    71
    Likes Received:
    3
    Best Answers:
    4
    Trophy Points:
    0
    #7
    Where is your "color" value coming from? Do you pull it from a form? Do you pull it from a database? Do you hard code it? You're trying to use the value for $color, but it's not defined anywhere. If you define it as $color = $_POST['color'] but you haven't submitted a form or something that adds "color" to the post variable, you will still get an empty value. Where do you GET the color from?
     
    kbduvall, May 26, 2012 IP
  8. KangBroke

    KangBroke Notable Member

    Messages:
    1,026
    Likes Received:
    59
    Best Answers:
    4
    Trophy Points:
    265
    #8

     header('location: http://www..com/Admin/admin_home.php?tournament_id='.urlencode($tournament_id).'&color='.urlencode($tournament_id));
             exit;
    PHP:
    passes it as admin_home.php?tournament_id=15&color=

    when im showing the same variable
     
    KangBroke, May 26, 2012 IP
  9. #9
    Is the color stored in the database? If it is, maybe you should replace $color=$_POST['color']; with $color=$row['color']; after: $row = mysql_fetch_array($query);
     
    kbduvall, May 26, 2012 IP
  10. KangBroke

    KangBroke Notable Member

    Messages:
    1,026
    Likes Received:
    59
    Best Answers:
    4
    Trophy Points:
    265
    #10
    Now im up to this

    <?php
    	include('../Admin/db_config.php');		
    	$tournament_id=$_REQUEST['tournament_id'];
    
    	$username = isset($_REQUEST['txtUser'])?$_REQUEST['txtUser']:'';
    	$password = isset($_REQUEST['txtPass'])?$_REQUEST['txtPass']:'';
    
    		
    
    $sql = "SELECT color FROM `tournament` ";
    	$query1 = mysql_query($sql);
    	$row2 = mysql_fetch_array($query1);
    
    
    	$sql = "SELECT * FROM `team_registration` ";
    	$query = mysql_query($sql);
    	while($row = mysql_fetch_array($query)){
    	if(($row['user_id'] == $username) && ($row['password'] == $password))
    
    
    {
    
    
    
    
    		$_SESSION['logged']=true;
    		$_SESSION['user_id']=$username;
    		$_SESSION['team_registration_id']=$row['team_registration_id'];
    
    		header('location:team_manager_home.php?tournament_id='.$row['tournament_id'].'&color='.$row2['color']);
    		 exit;
    
    
    
    
    
    
    	}
    	}//while
    	
    		header('location:index.php?tournament_id='.$tournament_id.'&color='.$color);
    		
    	
    	
    ?>
    PHP:

    and for the $color. it is pulling the very first column of that row, not the one corresponding with the correct value.
    Now both Variables are passed to the Header URL.

    Only problem now is, It is using the first row of that table.

    $sql = "SELECT color FROM `tournament` ";
    $sql['color'] retuns the first row not the correct row
     
    KangBroke, May 27, 2012 IP