I'm trying to verify some login information from a form. The security isn't that important as this is just a small social media thing for my friends and myself and I have backups so I don't really mind getting hacked, I'm just learning php.
Here is the error I'm getting:
Fatal error: Call to a member function fetch_assoc() on a non-object
in /srv/disk4/2177948/www/website.com/postlogin.php on line 34
Here is the code:
Line 34 is marked out with //
Note: The connection information is censored, it works perfectly in the script.
session_start();
$usrName = $_POST['logInName'];
$pass = $_POST['logInPass'];
$servername = "censored";
$username = "censored";
$password = "censored";
$db_name = "censored";
$conn = mysqli_connect($servername, $username, $password, $db_name);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT usrName FROM loginInfo WHERE usrName='" . $usrName . "';";
$result = mysqli_query($conn,$sql);
if ($conn->query($sql) == TRUE) {
while ($row = $result->fetch_assoc()) {
$retrievedUsrName = $row["usrName"];
}
} else {
echo 'Error: ' . $conn->error;
}
$result->free;
if ($retrievedUsrName == $usrName) {
$sql2 = "SELECT pw FROM logininfo WHERE pw='" . $pass . "';";
$result2 = mysqli_query($conn,$sql2);
while ($row = $result2->fetch_assoc()) { //Line 34
$retrievedPass = $row["pw"];
}
} else {
echo 'Fant ikke brukernavnet i databasen. Spør Tommy.';
}
if ($retrievedPass == $pass) {
header('Location: index.php');
} else {
echo 'Fant ikke passordet i databasen. Spør Tommy.';
}
$result->free;
$conn->close;
?>
No comments:
Post a Comment