Sessions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Slavender
Forum Newbie
Posts: 4
Joined: Thu Apr 30, 2009 7:43 am

Sessions

Post 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
Last edited by Benjamin on Thu Apr 30, 2009 12:18 pm, edited 1 time in total.
Reason: Changed code type to php.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Sessions

Post 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();
Post Reply