I've got a login screen all setup but my php code doesn't seem to work with it. Can't find the issue either as the details I'm entering are correct but it is not displaying either of the outputs. 1 - being proceed to next page. 2 - being display message saying incorrect details. Atleast thats what I think it should be doing. My code is here;
<?php
session_start();
if (isset($_POST['login'])):
require_once('my_connect.php');
$username=$_POST['username'];
$password=$_POST['password'];
$my_query="SELECT * from loanusers where username='$username' AND password='$password'";
$result= mysqli_query($connection, $my_query);
if (mysqli_num_rows($result) >0):
while ($myrow = mysqli_fetch_array($result)):
$_SESSION['userid'] = $myrow["userid"];
$_SESSION['username'] = $myrow["username"];
$_SESSION['password'] = $password;
$_SESSION['usertype'] = $myrow["usertype"];
$_SESSION['authenticated'] = true;
echo "<b> Hi ".$_SESSION['username']." (ID: ".$_SESSION['userid']."), You are now logged in!</b>";
endwhile;
//header('Location: homepage.php');
else:
echo "<b>Username or Password incorrect</b>";
endif;
mysqli_close();
endif;
require_once 'loginheader.php';
?>
<html>
<body>
<h2>User Login</h2>
<div id="loginp"><p>Need an Account? <a href='adduser.php'><b>Sign Up</b> </p></a></div>
<table>
<form method="POST" action="homepage.php" autocomplete="off">
<input type="text" name="username" placeholder="Username...">
<br><br>
<input type="password" name="password" placeholder="Password...">
<br><br>
<input type="submit" name="loanlogin" value="Sign In" onclick="window.location.href='homepage.php'">
</form>
</table>
<br>
<div id="loginp"><p>Forgot your Password?<b> Click Here</b></p></a></div>
<body>
<html>