Thread: $_SESSION data

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    8
    Rep Power
    0

    $_SESSION data


    Right Now I am trying to assign something to the variable $SESSION['subs']

    The script below is intended to check the database against the name acquired in the POST form then it starts a session for that user and assigns the username as session data.

    What I need it to do is take data from the database to assign it as another session item called $_SESSION ['subs']

    input Username = jim
    write to SESSION['subs'] Subscription = do

    subs is short for subscription and essentially it will work as a switch for an if statement later on.

    Code:
    // username and password sent from form 
    $username=$_POST['user1']; 
    $password=$_POST['pass1']; 
    
    $result = mysql_query("SELECT * FROM users");
    $info =  mysql_fetch_row ($result);
    $subs= $info['subs'];
    
    
    
    $ip=$_SERVER['REMOTE_ADDR'];
    
    $_SESSION['user'] = $username;
    $_SESSION['subs'] = $Subs;
    
    
    // To protect MySQL injection (more detail about MySQL injection)
    $username = stripslashes($username);
    $password = stripslashes($password);
    $Subs = stripslashes($subs);
    
    $username = mysql_real_escape_string($username);
    $password = mysql_real_escape_string($password);
    $Subs = mysql_real_escape_string($subs);
    
    $sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'";
    
    $result=mysql_query($sql);
    
    // Mysql_num_row is counting table row
    $count=mysql_num_rows($result);
    
    // If result matched $username and $password, table row must be 1 row
    
    mysql_connect("BLAHBLAH")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    
    $query="INSERT INTO userlog (username,time,ip) VALUES('$username',CURRENT_TIMESTAMP,'$ip')";
    $query1 = mysql_query($query);
    
    
    if($count==1){
    
    
    				session_register("username");
    				session_register("password");
    				session_register("subs");
    				 
    				
    				header("location:successlog.php");
    				
    			}
    	
    		else 
    			{
    				echo "Wrong Username or Password";
    			}
    ?>


    Major Thank you in advance to whom ever figures this out.
  2. #2
  3. No Profile Picture
    Lost in code
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 2004
    Posts
    8,298
    Rep Power
    7170
    $subs and $Subs are different variable names.
    PHP FAQ

    Originally Posted by Spad
    Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

IMN logo majestic logo threadwatch logo seochat tools logo