I have a registration page which hashes passwords and stores it in MySQL. I am having an issue upon login where PHP is not recognizing the username and password. I have searched for answers, and tried to implement the many examples but none have worked. Below is the code:
?php
session_start();
if(isset($_POST['insert'])){
// username and password sent from form
$hostname = "localhost";
$username = "root";
$password = "Passw0rk1";
$databaseName = "change_management";
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
$user = $_POST['user'];
$passcode = $_POST['passcode'];
$sql = "SELECT * FROM admin WHERE username = '$user' and passcode ='".md5($passcode)."'";
$result = mysqli_query($connect,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
// If result match $myusername and $mypassword, table row must be 1 row
if($count ==0) {
echo "Invalid Credentials";
}else {
I know the credentials I am inputting are present in the SQL but I am getting 'Invalid Credentials' echoed on the screen.
Here is the registration page incase there is an issue here:
?php
if(isset($_POST['insert']))
{
$hostname = "localhost";
$username = "root";
$password = "Passw0rk1";
$databaseName = "change_management";
$user = $_POST['user'];
$passcode = $_POST['passcode'];
$connect = mysqli_connect($hostname, $username, $password, $databaseName);
$sql = "INSERT INTO `admin` (`username`, `passcode`) VALUES('$user', '".md5('$passcode')."')";
$result = mysqli_query($connect,$sql);
if($result)
{
echo "Added successfully";
}
else{
echo $connect->error;
}
}
?>