I am creating a login form and am having trouble with it not successfully logging in. My form looks like this
<form method="post" action="phpScripts/loginProcess.php">
<input type="text" name="uname" value="" placeholder="Username">
<input type="password" name="pass" value="" placeholder="Password">
<input id="submit" type="submit" value="submit">
</form>
I have already checked and I am connecting to the database, and my uname and pass are both correct. I have double checked plenty of times. The issue is within my query. Here is the loginProcess.php file
<?php
require_once ('dbconn.php');
if(isset($_POST['login'])){
$uname = mysqli_real_escape_string($_POST['uname']);
$pass = mysqli_real_escape_string($_POST['pass']);
$query = mysql_query ("SELECT * FROM staff WHERE uname='$uname'");
$numrows = mysql_num_rows($query);
if ($numrows !=0){
die("Success!!");
}
else{
die("That user doesnt exist");
}
}
else{
echo "Username or Password incorrect";
}
?>
With the help of Fred-ii- I was able to figure out my mistakes and really quickly fix my login issue! I wanted to supply the code I used to login in case anyone else came across this problem.
Here is the code that I am using to login. I feel as I can make it a little less redundant with the execute and $userSql/$pwSql. Any suggestions to clean this up would be greatly appreciated!
<?php
ini_set('display_errors', 1); error_reporting(E_ALL);
require_once ('dbconn.php');
$uname = $_POST['uname'];
$pass = $_POST['pass'];
$userSql = "SELECT * FROM staff WHERE uname=:uname";
$getUser = $conn->prepare($userSql);
$getUser->execute(array(
':uname' => $uname
));
if($getUser->rowCount()){
$pwSql = "SELECT pass FROM staff WHERE uname =:uname";
$getPw = $conn->prepare($pwSql);
$getPw->execute(array(
':uname' => $uname
));
$pw = implode($getPw->fetch(PDO::FETCH_ASSOC));
if(password_verify($pass,$pw)){
header("Location: ../../staffHome.php");
}else{
echo "Oops! You have entered in an incorrect password!";
}
}else{
echo "Oops! That user doesn't exist!";
}
?>