SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Login code

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    99
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Login code

    Hey there,

    i am trying to work on the login code, i would like to know if there is a PDO function to return the total number of found rows. If i remeber i thought there was a function call rowCount but maybe i am mistaken, but i don't think it well do what i want it to do. Thanks for the help PDO is still new to me.

  2. #2
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The rowCount method still does exist in PDO http://www.php.net/manual/en/pdostatement.rowcount.php

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2012
    Posts
    99
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Here's the code i tried:

    PHP Code:

    <?php

     $Dbuser 
    'colin';
     
    $passwordDb 'qeMQjea5uqdZc3W8';


    try {
    $dbconnect = new PDO("mysql:host=localhost;dbname=ageasy",$Dbuser,$passwordDb);
        }

    catch (
    PDOException $e)
        {
            echo 
    '<p class="db_Erorr">We can not connect to the database at this time. Please try at a later time</p>'.$e->getMessage();  
        }



    $emailUnSafe $_POST['email'];
    $email strip_tags(trim($emailUnSafe));

    $passWdUnSafe $_POST['password'];
    $passWdRaw stripslashes(htmlspecialchars(trim($passWdUnSafe)));
    $passwd hash('sha512',$passWdchar);
    $salt['0'] = 'salt';
    $salt['1'] = 'salt';
    $password $salt['1']."".$passwd."".$salt['0'];

    $sql 'SELECT COUNT(*) FROM members WHERE email=:email AND password=:password';
    $s $dbconnect->prepare($sql);

    $s->bindValue(':email',$email);
    $s->bindValue(':password'$password);

    if (
    $res $s->execute())
        {
            if(
    $res->fetchColumn == 1)
                {
                    
    $sql "SELECT * FROM members WHERE email=:email AND password=:password";
                    
    $res->setFetchMode(PDO::FETCH_OBJ);
                    while(
    $row $result->fetch())
                    {
                        
    $_SESSION['email'] = $row->email;
                        
    $_SESSION['userId'] = $row->id;
                        
    $_SESSION['nameFirst'] = $row->nameFirst;
                        
    $_SESSION['farmName'] = $row->farmName;
            
                    }
            
                }
            else 
                {
                    echo 
    '<p> We could not find your account please check the email or password</p>';
                }
        }
    I need a bit of help, i have little clue how to do row count's in PDO

  4. #4
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,189
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    The link i posted has all the information you need, all you need to do is the following.

    Change
    PHP Code:
    if ($res->fetchColumn == 1
    To
    PHP Code:
    if ($res->rowCount() > 0


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
  •