mysql - Php PDO connection to database -
i have database 2 table. students , profesors. create 1 more login table , there email , passwords students , profesors. want create student try login send him on student.php , when profesor try login send him on profesor.php
i try code, return me 1. not options..
if(isset($_post['submit'])){ $sql= "select count (*) `students` , 'profesors' `username` = :username , `password` = :password "; $result = $connection->prepare($sql); $result->bindparam(":username" ,$_post['username']); $result->bindparam(":password" ,$_post['password']); $result->execute(); $num=$result->rowcount(); if($num > 0){ header("location:index.php"); }else{ header("location:login.php"); }
i need idea, how change datebase or login code.
i not let professors , student use same login. answer question change query following:
select user_type `login_table` `username` = :username , `password` = :password
once query return result check user_type field , redirect accordingly.
$num=$result->rowcount(); if($num > 0){ $data=$result->fetch(); if($data['professor']){ header("location: professor.php"); }else{ header("location: student.php"); } }else{ header("location:login.php"); }
Comments
Post a Comment