Extract username from session and add to database

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Extract username from session and add to database

    Hi, I have the following problem:

    I have a html form for articles and another file that insert data into database. I want to write in the database the id of the author and in the file that insert information in the database I got this code:

    PHP Code:

    $sname 
    $_SESSION['username'];
    $select "SELECT * FROM users WHERE name = '$sname'";
    $result mysql_query($select) or die (mysql_error());
    while (
    $curent_user mysql_fetch_assoc($result)){
    $author $curent_user['id'];

    And in the query the $author, but don't work, write 0 in the author_id field but the id of my account in the users table is 5.
    How can I make this to write the good id?
    Sorry for my english and thanks in advance!

    #2
    Try...

    PHP Code:
    $sname = !empty($_SESSION['username']) ? $_SESSION['username'] : null;
    $select 'SELECT * FROM users WHERE name = "'.$sname.'"';
    $result mysql_query($select) or die (mysql_error());
    $curent_user mysql_fetch_array($result)
    $author $curent_user['id']; 
    <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

    Comment


      #3
      Thank you, this works like a charm.

      Comment


        #4
        You're welcome.
        <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

        Comment

        Working...
        X