Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PEAR DB Login Script

    the variable "$count" allways returns as 0 making the login a failure. where is my error?

    PHP Code:

    if(empty($_POST['name']) || empty($_POST['pass'])) 
    {  ?> 
        <b>Fill All Details </b> 
                  <?php exit; 

    else 

        
    //Colllect the details and validate 
        
    $time time(); 
        
    $name $_POST['name']; 
        
    $pass md5($_POST['pass']); 
        
    $check $_POST['set'];  
            
            
    //Run Query
            
    $stmt "SELECT * FROM {$tb_prefix}users where username='$name' and password='$pass'";   
        
    $sql $dbh->getAll($stmtDB_FETCHMODE_ASSOC);
            
            
    //Error Message
            
    if (PEAR::isError($sql)) {
        echo 
    "An error occurred while trying to run your query.";
            exit;}
            
            
    //Counts Rows
            
    $count count($sql);
            
            echo 
    "$count<br>";
            echo 
    "$sql<br>";
            
            if (
    $count == 1
        { 
            
    $cookie_data $name.'-'.$pass;   
            if(
    $check=='ON'
            { 
                if(
    setcookie ("cookie_info",$cookie_data$time+3600)==TRUE
                { 
                    echo 
    "Cookie SET".$cookie_data?> 
                    <a href='logout.php'>Logout</a> 
                     
                <? 
            } 
        } 
        else 
        { 
            echo 
    "Authentication Failed"
            exit; 
        } 
         

    ?>

    why dose $count allways equal zero when it should equal one?where is the error?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    frankfurt, german banana republic
    Posts
    1,848
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Perhaps no result is found for the SQL query? Have you printed out the generated query and run that through phpMyAdmin, to see if the result is as expected? That's the only possible explanation I have so far, your DB code looks ok otherwise.
    De gustibus non est disputandum.

  • #3
    New Coder
    Join Date
    Aug 2003
    Posts
    79
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm i guess it has something to do with md5 encryption. i think i might have messed up with that. i'll have to check again i guess...


  •  

    Posting Permissions

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