SitePoint Sponsor

User Tag List

Results 1 to 13 of 13

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    14
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Login in PHP Using PDO Error!

    Code:
    <?php session_start();
    include 'conn.php';
    if(isset($_POST) && count($_POST)>0) {
    try
    {
        $user=$_POST['user'];
        $pass = $_POST['pass'];
        $secure=password_verify($pass,PASSWORD_DEFAULT);
        $query = "SELECT * FROM signup WHERE Username=:users AND Password=:pass";
        $result=$conn->prepare($query);
        $result->execute(array('users'=>$user,':pass'=>$secure));
        if($result->fetchColumn()>0)
        {
            // Set username session variable
            $_SESSION['user'] = $user;
            // Jump to secured page
            header('location:index.php');
        }
        else
        {
            header("location:signin.php");
        }
    }
    catch(PDOException $e){
            echo 'ERROR', $e->getMessage();
        }
    
    }
    
    ?>
    Why my login code is not working?

  2. #2
    SitePoint Mentor silver trophy
    Rubble's Avatar
    Join Date
    Dec 2005
    Location
    Cambridge, England
    Posts
    2,407
    Mentioned
    81 Post(s)
    Tagged
    3 Thread(s)
    Why my login code is not working?
    What is not working and what error do you have ?

  3. #3
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    14
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    The login code is not working and it will show no error, the main issue is that it will not login...

  4. #4
    SitePoint Addict bronze trophy mawburn's Avatar
    Join Date
    Apr 2014
    Posts
    213
    Mentioned
    6 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by msz900 View Post
    The login code is not working and it will show no error, the main issue is that it will not login...
    I laughed harder at this than I should have. lol

    For real though, that doesn't help at all. If you want someone to help you with the code, you need to include the actual errors. Otherwise they are just looking for a typo or a syntax issue.

    Code:
    error_reporting(E_ALL);
    ini_set('display_errors', 1);
    Add that to the top of your page then paste the error here.

  5. #5
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,836
    Mentioned
    73 Post(s)
    Tagged
    6 Thread(s)
    Quote Originally Posted by msz900 View Post
    The login code is not working and it will show no error, the main issue is that it will not login...
    Try this and you should be able to see what is happening:

    PHP Code:

    <?php 
    error_reportin
    (-1); // maximum error reporting 
    ini_set('display_errors'true);

    session_start();
    // include 'conn.php';
    require 'conn.php';
    if(isset(
    $_POST) && count($_POST)>0)
    {
        try
        {
    vd($_POST__LINE__);
            
    $user   $_POST['user'];
            
    $pass   $_POST['pass'];
            
    $secure password_verify($pass,PASSWORD_DEFAULT);
            
    $query  "SELECT * FROM signup WHERE Username=:users AND Password=:pass";
    vd($query__LINE__);

            
    $result $conn->prepare($query);
            
    $result->execute(array('users'=>$user,':pass'=>$secure));
            if(
    $result->fetchColumn()>0)
            {
                
    // Set username session variable
                
    $_SESSION['user'] = $user;
                
    // Jump to secured page
                
    header('location:index.php');

            }else{
                
    header("location:signin.php");
            }
    //endtry

        
    }catch(PDOException $e){
           echo 
    'ERROR'$e->getMessage();
        }

    }
    //endif

    //================================================
    //  Debug
    //  usage:
    //             vd($val);
    //================================================
    function vd($val='$val Must be NULL'$line=0$print=TRUE)
    {
        echo 
    '<pre>';
            echo 
    '$line = ' .$line;
            if( 
    $print )
            {
               
    print_r($val);
            }else{
               
    var_dump($val);
           }
        echo 
    '</pre>';
    }
    Please note:
    1. the above script has not been tested because of hard-drive failure and still have to instal Localhost, etc, etc, etc, etc, etc
    2. header redirect will not work because of screen output from vd($val, __LINE__);
    3. remove vd($val, __LINE__); once errors eliminated.
    Last edited by John_Betong; Apr 25, 2014 at 19:20. Reason: spelling, not my fortay
    Learn how to be ready for The New Move to Discourse

    How to make Make Money Now with a *NEW* look

    Be sure to congratulate Patche on earning Member of the Month for July 2014

  6. #6
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    14
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question

    Quote Originally Posted by John_Betong View Post
    Try this and you should be able to see what is happening:

    PHP Code:

    <?php 
    error_reportin
    (-1); // maximum error reporting 
    ini_set('display_errors'true);

    session_start();
    // include 'conn.php';
    require 'conn.php';
    if(isset(
    $_POST) && count($_POST)>0)
    {
        try
        {
    vd($_POST__LINE__);
            
    $user   $_POST['user'];
            
    $pass   $_POST['pass'];
            
    $secure password_verify($pass,PASSWORD_DEFAULT);
            
    $query  "SELECT * FROM signup WHERE Username=:users AND Password=:pass";
    vd($query__LINE__);

            
    $result $conn->prepare($query);
            
    $result->execute(array('users'=>$user,':pass'=>$secure));
            if(
    $result->fetchColumn()>0)
            {
                
    // Set username session variable
                
    $_SESSION['user'] = $user;
                
    // Jump to secured page
                
    header('location:index.php');

            }else{
                
    header("location:signin.php");
            }
    //endtry

        
    }catch(PDOException $e){
           echo 
    'ERROR'$e->getMessage();
        }

    }
    //endif

    //================================================
    //  Debug
    //  usage:
    //             vd($val);
    //================================================
    function vd($val='$val Must be NULL'$line=0$print=TRUE)
    {
        echo 
    '<pre>';
            echo 
    '$line = ' .$line;
            if( 
    $print )
            {
               
    print_r($val);
            }else{
               
    var_dump($val);
           }
        echo 
    '</pre>';
    }
    Please note:
    1. the above script has not been tested because of hard-drive failure and still have to instal Localhost, etc, etc, etc, etc, etc
    2. header redirect will not work because of screen output from vd($val, __LINE__);
    3. remove vd($val, __LINE__); once errors eliminated.
    D
    Dear Any simple method please?

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,174
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    @msz900 ; simpler that someone else giving you some code to try?

    What error messages did you get?

  8. #8
    SitePoint Member
    Join Date
    Jan 2013
    Posts
    14
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    this is the message
    Call to undefined function vd() in G:\xammp\htdocs\leave_system_pdo\public\login.php on line 6


Tags for this Thread

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
  •