SitePoint Sponsor

User Tag List

Results 1 to 12 of 12
  1. #1
    SitePoint Evangelist Raining_Curses's Avatar
    Join Date
    May 2005
    Posts
    560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Creating SESSIONS help please

    Hi all, Im in the process of slowly making an online RPG, it is in very early development lol.

    At the moment im working on the profiles and having trouble doing so. I thought a session would be a good way to store a signature, then output it to a profile page. The signature is stored in the database, so i need to get the signature out of the database and into the session.

    This is the code i have used to make the session:

    $sql = "SELECT sig FROM users WHERE username = '".$_POST['uname']."'";
    $sig = mysql_query($sql) or die(mysql_error());

    $_SESSION['signature'] = ($sig)

    Now when i try to call the session using

    echo $_SESSION['signature'];

    I get the words 'Resource id #13

    I dont have a clue what is wrong please help.

    Thanks

  2. #2
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Baku, Azerbaijan
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $sig is the resource id returned from the mysql_query function. $sig has to be result.

    $sql = "SELECT sig FROM users WHERE username = '".$_POST['uname']."'";
    $sig = mysql_query($sql) or die(mysql_error());

    $sgn = mysql_result($sig, 0, 0);

    $_SESSION['signature'] = ($sgn);

    echo $_SESSION['signature'];

    Now you should get the name of the user.

  3. #3
    SitePoint Evangelist Raining_Curses's Avatar
    Join Date
    May 2005
    Posts
    560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh ok then i get it now i needed another bit of code opps lol thanks mate ill just test that. Im still learning php so some bits are new to me.


  4. #4
    SitePoint Evangelist Raining_Curses's Avatar
    Join Date
    May 2005
    Posts
    560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bingo, problem sloved thanks mate! Very much appreciated.

  5. #5
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Baku, Azerbaijan
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm also a newbie strolling around the forum to learn new things, tryint to solve promlems I come across in scripts

    Glad that it helped

  6. #6
    SitePoint Guru arunkumar's Avatar
    Join Date
    Jan 2005
    Location
    India:Chennai
    Posts
    827
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi,,

    have your problem solved??????????????????????????
    Where there is a will there is a way
    ArunKumar

  7. #7
    SitePoint Evangelist Raining_Curses's Avatar
    Join Date
    May 2005
    Posts
    560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes but i have another question lol. I used this code to create one session

    $sql = "SELECT sig FROM users WHERE username = '".$_POST['uname']."'";
    $res = mysql_query($sql) or die(mysql_error());
    $sig = mysql_result($res, 0, 0);

    Now can i use the variables $sql and $res to create another session like that or do i need to have different variable names?

    Thanks

  8. #8
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Baku, Azerbaijan
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I didn't get what you mean by creating another session. Would you explain a little more?

  9. #9
    SitePoint Evangelist Raining_Curses's Avatar
    Join Date
    May 2005
    Posts
    560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok...... Well i have a session called $_SESSION['signature']

    And to create that i used the code:

    $sql = "SELECT sig FROM users WHERE username = '".$_POST['uname']."'";
    $res = mysql_query($sql) or die(mysql_error());
    $sig = mysql_result($res, 0, 0);

    $_SESSION['signature'] = ($sig);

    Now i want another session called $_SESSION['email'] and that also requires me to get data from the table and run the query so if i use the code:

    $sql = "SELECT email FROM users WHERE username = '".$_POST['uname']."'";
    $res = mysql_query($sql) or die(mysql_error());
    $email = mysql_result($res, 0, 0);

    $_SESSION['email'] = ($email);

    Would that work?? Or do i need to use different variables than $sql and $res??

    Thanks hope that makes more sence

  10. #10
    SitePoint Evangelist djdykes's Avatar
    Join Date
    Feb 2005
    Location
    Chester, Cheshire
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if you need to store the values in the session why not do it directly

    PHP Code:

    $_SESSION
    ['sig'] = mysql_result($res0,0); 
    is that what you meant? you were a little vague

  11. #11
    SitePoint Zealot
    Join Date
    Apr 2005
    Location
    Baku, Azerbaijan
    Posts
    156
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Raining Curses,

    it's better to select two datas from the table in one query and then store it in different session variables.

    $sql = "SELECT sig, email FROM users WHERE username = '".$_POST['uname']."'";
    $res = mysql_query($sql) or die(mysql_error());

    $_SESSION['signature'] = mysql_result($res, 0, 0); //signature
    $_SESSION['email'] = mysql_result($res, 0, 1);//email

  12. #12
    SitePoint Evangelist Raining_Curses's Avatar
    Join Date
    May 2005
    Posts
    560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes that is it, thanks mate i got a bit confused with the variables but its ok now, i will just go and test it on my site, back later people.

    Bye. Thanks for all the help


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •