mysql - how to know if admin in PHP mysqli login page -
i have php login page , mysql table ( users : id,username,password,admin )
the admin column's data type bit , default 0 , if admin value of users.admin= 1
so php code working except dont know how fetch admin in prepared statement because not input username or password :\
$username='blabla'; $password='blabla'; if ($stmt = $mysqli->prepare("select * `users` username=? , password=? limit 1")) { /* bind parameters markers */ $stmt->bind_param("ss",$username,$password); $stmt->execute(); $stmt->bind_result($username,$password); $stmt->store_result(); if($stmt->num_rows == 1) //to check if row exists { while($stmt->fetch()) //fetching contents of row {$_session['username'] = $username; //$_session['admin'] = $admin; (not added yet) echo "1"; exit(); } } else { echo "2"; return; } $stmt->close(); $stmt->free_result(); } $mysqli->close();
you can session.
firstly set session in login page need use foreache datas in array can see if use command
if($stmt->num_rows == 1) //to check if row exists { $a=$stmt->fetch(); die(r_print($a));
and see colum name
you can set sessşons , variables
like $admin =$a[0]["colum name"]; if($admin==1) $_session["usertype"]="admin";
and check if admin logined start code
if($_session["usertype"]=="admin"){ //write code here //only admin can see these part }
Comments
Post a Comment