为什么pdo没反应?

时间:2019-07-10 13:36:22

标签: php mysql pdo

我是HTML和PHP的新手,我试图制作一个登录页面,但没有任何反应,也没有回显任何信息。我​​不知道数据库是否已建立连接,这是我的PHP代码:

   <?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();  
   }  
   ?>

请任何人都可以帮助我。

0 个答案:

没有答案