I've been trying to write a PHP program that gives users the ability to register for an account and login once registered. I've managed to prevent the registration of multiple usernames and store all registered usernames and the corresponding passwords in a SQL table, but I'm trying to get login working by verifying passwords, and PHP doesn't seem to be recognizing anything from SQL. I've tried countless variations of mysqli_fetch_array and mysqli_fetch_assoc to no avail. Entirety of PHP code is posted below, with comments specifying the most relevant parts.
<?php session_start(); ?>
<html>
<head>
<title>Test Form</title>
</head>
<body>
<link rel="stylesheet" type="text/css" href="main.css" />
<?php
include('mydbinfo.php');
$conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
if ($conn->connect_error) {
echo("<font color='red'><p>Unable to connect to the database system</font>"."<font color='red'>Please try later.</font></p>");
exit();
}
if($_POST["email"].value == "" or $_POST["password"].value == "") {
print("<font color='red'><p>Sorry, you must enter values into each field.</font></p>");
} else {
$mail = $_POST["email"];
$_SESSION["sessUsername"] = $mail;
$pass = $_POST["password"];
$query = "SELECT user_password FROM logins WHERE email='$mail'";
$result=mysqli_query($conn,$query);
while($name = mysqli_fetch_array($result)) {
array_push($names,$name['email']);
for($n = 0; $n < count($names); $n++) {
if($names[$n] == $name['email']) {
$names++;
}
}
}
//Number of instances of SQL query result found in table.
$count = mysqli_num_rows($result);
if($count > 0) {
//Supposed to contain password which corresponds to a given user ID.
//This is the main issue.
$new=mysqli_fetch_array($result);
if($pass == $new) {
print "<font color='red'><p>Welcome back, $mail!</p></font>";
} else {
print "<font color='red'>Your reservation was invalid.</font>";
print($pass);
print($result);
}
} else {
echo "<font color='red'>Not found in table.</font>";
}
}
?>
</body>
</html>
<?php>