Thread: Login

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    8
    Rep Power
    0

    Login


    This is simple login code and in the user.php it seems to hangup in the construct section (public function __construct), No errors but login does not work.

    Here is the three files index, connection and user.php.

    index

    PHP Code:
    <?php
    ini_set
    ('display_errors',1);
    ini_set('display_startup_errors',1);
    error_reporting(-1);
    include_once (
    'includes/user.php');

    if(isset(
    $_Post['submit'])){
        
    $name $_Post['user'];
        
    $pass $_Post['pass'];
        
        
    $object = new User();
        
    $object->Login($name$pass);
    }
    ?>    
    <html>
    <head></head>
    <body>
    <form method="post" action="index.php">
        Username: <input type="text" name="user"/>
        Password: <input type="text"name="pass"/>
        <input type="submit" name="submit" value="Login"/>
    </form>    
    </body>
    </html>
    connect
    PHP Code:
    <?php 
    class Connection{

        public function 
    dbConnect(){
            return new 
    PDO("mysql:host=localhost; dbname=libertc0_larlbr""libertc0_dobbin""d****");
        }
    }
    ?>
    user
    PHP Code:
    <?php

    include_once('connect2.php');
            

    class 
    User{

        private 
    $db;

        public function 
    __construct(){
        
            
    $this->db = new Connection();
            
    $this->db $this->db->dbConnect();
            
        }
        
             public function 
    Login($name$pass) {
                if(!empty(
    $name) && !empty($pass)){
                    
    $st $this->db->prepare("select * from users where user=? and pass=?");
                    
    $st->bindParam(1$name);    
                    
    $st->bindParam(2$pass);
                    
    $st->execute();
                    
                    if(
    $st->rowCount() == 1){
                        echo 
    "User verified Access Granted.";
                        
    header('Location: survey.php');
                    }else{
                        echo 
    "Incorrect Username or Password";
                    }        
                }else{
                    echo 
    "Please enter Username and Password";
                }
        }
    }    
    ?>
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2009
    Location
    Nebraska, USA
    Posts
    829
    Rep Power
    275
    you have $_Post , but, it needs to be $_POST ...it has to be all capital letters.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    8
    Rep Power
    0
    OMG That was it!!

IMN logo majestic logo threadwatch logo seochat tools logo