0

I am new with HTML and PHP I tried to make a login page but nothing happened and nothing is echoed.Idon't know if the connection has established with the database, This my PHP code:

   <?php  
   session_start();  
   $host = "localhost";  
   $username = "root";  
   $password = "";  
   $database = "testdb";  
   $message = "";  
   try  
   {  
     $connect = new PDO("mysql:host=$host; dbname=$database",        $username, $password);  
     $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);  
     if(isset($_POST["btnsubmit"]))  
     {  
       if(empty($_POST["username"]) || empty($_POST["password"]))  
       {  
         $message = '<label>All fields are required</label>';  
       }  
       else  
       {  
         $query = "SELECT * FROM login WHERE username = :username AND        password = :password";  
         $statement = $connect->prepare($query);  
         $statement->execute(  
         array(  
           'username'=>$_POST["username"],  
           'password'=>$_POST["password"]  
               )  
         );  
         $count = $statement->rowCount();  
         if($count > 0)  
         {  
           $_SESSION["username"] = $_POST["username"]; 
           echo "welcome"; 
           header("location:login_success.php");  
         }  
         else  
         {  
           $message = '<label>Wrong Data</label>';  
         }  
       }  
     }  
   }  
   catch(PDOException $error)  
   {  
     $message = $error->getMessage();  
   }  
   ?>

Please anyone can help me.

0 Answers0