Page 1 of 1

Sessions

Posted: Thu Apr 30, 2009 7:59 am
by Slavender
Hi, I'm new to this Forum and I have a problem with Sessions that I've wrecking my head over for the last day I suppose.

So here it is: Basically, I want to use a Session Variable. I want to use it for submitting Blogs. I have a MYSQL table, which holds a pNO(picture number), userName and uPost (Users Post).

Basically, I have the Sessions working in my Website.

However, I want to read a Session Variable and assign it to a normal variable. I will then use it in a Query for my MYSQL database.

This is the code I came up with:

Code: Select all

 
 
if (session_is_registered('userName')){
    
 
/////////////// Get pNumber//////////////////////////////
    $Query = "SELECT count(DISTINCT piNO) FROM tbl_Iblog";
    $Result = @mysql_query ($Query);
    $QueryResult = mysql_fetch_array($Result, MYSQL_NUM);   
    $pNIncrement = $QueryResult[0] + 1;
    
    $uName = $userName; // <-------------- That is me attempting to use the Session Variable.
    
    
    /////////////// POST/////////////////////////////////////
      
        $Query = "insert into tbl_Iblog values('$pNIncrement','$uName','$post')";
        mysql_query ($Query);
    
}
 
 

Ok, thats basically the Just of the Code, I just need to be able to assign a Session Variable to a Normal Variable.

Anyone able to propose a solution!?

Kind Regards,

David Harvey

Re: Sessions

Posted: Thu Apr 30, 2009 8:11 am
by requinix
Use $_SESSION. It's just like $_GET and $_POST except it uses session variables.

Code: Select all

session_start();
 
// to store a variable in a session
$_SESSION["key"] = $value;
// to get the variable back out
$value = $_SESSION["key"];
// to destroy the variable (but not the session)
unset($_SESSION["key"]);
// to destroy the entire session
session_destroy();