SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    UPDATE not going through

    Hey,

    I have a log in script that I'm trying to set the session into a table and then retrieve it for further use later. But it's not updating the table properly. In fact, it's not updating at all.

    PHP Code:
    $user = new User('localhost''root''''db');
        
    $username sanitize($_POST['username']);
        
    $password sanitize($_POST['password']);
        
        if (
    $user->loginUser($username$password)) {
          
    session_start();
          
    $user->setSession(session_id());
          
    $_SESSION['firstname'] = $user->getFirstname();
          
    $_SESSION['lastname'] = $user->getLastname();
          
    $_SESSION['username'] = $user->getUsername();
          
    $_SESSION['email'] = $user->getEmail();
          
    $_SESSION['logged'] = md5('true');
          
    $_SESSION['id'] = $user->getSession();
          
    //header('Location: index.html');
          
    echo $user->getSession() .'SESSION! <br />';
        }
        else {
          
    $error 'Wrong username/password';
        } 
    If you see I'm setting the session_id into the object and then I'm using getSession() to store it into a session.

    I echoed out getSession() and it's empty.

    I think the problem relies in the setSession method.
    PHP Code:
    public function setSession($strSession) {
        
    $this->hDB->query("UPDATE user 
                           SET session = '
    $strSession
                           FROM user 
                           WHERE id = '
    $this->getID'");
        
    $result $this->hDB->query("SELECT session 
                                     FROM user 
                                     WHERE id = '
    $this->getID'");
        
    $row $result->fetch_row();
        
    $this->session $row[0];
      } 
    I echoed getID() and it returns the correct 'id'.

    Anyone lend a hand?

  2. #2
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    1. Did you try doing the query MANUALLY in the database?
    2. I'm not sure why you're using 'FROM' - the syntax should be.. UPDATE tablename SET column = VALUE WHERE id=SOMETHING;
    3. Are you sure the table is named 'user' and not 'users'?
    Cross browser css bugs

    Dan Schulz you will be missed

  3. #3
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I corrected the syntax and removed FROM from the UPDATE. I tried to put it in manually and it worked fine.

  4. #4
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So your problem is solved, now that you removed that "FROM" bit from the actual scripting?
    Cross browser css bugs

    Dan Schulz you will be missed

  5. #5
    Non-Member
    Join Date
    Oct 2008
    Posts
    372
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I just fixed another error. I was doing $this->getID when I should have been using $this->id.

    Thanks!


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
  •