SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    using $_SESSION to pass table_id

    Hi All,

    I'm getting stuck when using the $_SESSION variables. I want to set a session variable based on a unique column in a MySQL table.

    Can I do this anythinglike this:

    PHP Code:
    $result=mysql_query("select loan_id from secure_loan 
                                where username = '"
    .$_POST['username']." '  )")
    $_SESSION['uniqueid'] == $result
    If this would wor, where abouts in the code would I put it.

    Thanks

  2. #2
    SitePoint Evangelist nick0161's Avatar
    Join Date
    Oct 2004
    Location
    australia
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $_SESSION['username'] = $row['username'
    is that what you meant?

    EDIT - sorry your code didn't come up before hand, i think you need to add a ; (Semicolin) before you start to declare your session variable after the )

  3. #3
    SitePoint Evangelist nick0161's Avatar
    Join Date
    Oct 2004
    Location
    australia
    Posts
    424
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try
    PHP Code:
    $result=mysql_query("select loan_id from secure_loan 
                                where username = '"
    .$_POST['username']." '  )");
    $_SESSION['uniqueid'] = $result


    Thanks[/QUOTE]

  4. #4
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks nick,

    I will try and figure out the best place for it.

  5. #5
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this:

    PHP Code:
     
    $result
    =mysql_query("select loan_id from secure_loan 
                                where username = '"
    .$_POST['username']." ' )"
    while ( 
    $row mysql_fetch_array($result)) {
         
    $loan_id $row['loan_id'];
         
    $_SESSION['uniqueid'] = $loan_id;

    Mark

  6. #6
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers Mark,

    Can I use this as a function, like so:

    PHP Code:
    function setSessionId($email$password)
        {
        
    $result=mysql_query("select loan_id from secure_loan 
                                where username = '"
    .$_POST['username']." ' )"
        while ( 
    $row mysql_fetch_array($result)) 
        {
        
    $loan_id $row['loan_id'];
        
    $_SESSION['uniqueid'] = $loan_id;
        }
        } 

  7. #7
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that should be a problem as long as you make sure it gets the right values for email and password

    Mark.

  8. #8
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    Bedford, UK
    Posts
    104
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, just confused myself.

    Would it work if I have this immediately underneath the function which inserts the loan_id into the table? Can it update and then retrieve from the same row within the same area of code?

    I basically want to put it in the login area (there is no registration, just put in email and password and your away.

    If the error checking is passed, the email and password are inserted into the table, making the loan_id populate, it then creates some other $_SESSION variables (email, password and logged_in), and I then want it to run the function above.

    Or would it have to go on the next page?

  9. #9
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah! that 'should' work fine!

    Mark.


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
  •