Hello on my first post!
Here I am trying to make a very simple login form because in a few weeks I have an assignment where I need to create something similar and I wanted to know the basics first. Now I figured this question might make you slap your head by it's easy solution but I just can't seem to figure it out myself.
So what I tried to do was just put my POST values in a MySQL query, and when a user is found display it in a while loop or else display the a warning but my code only result in an empty space.
I will spare you the details about the index.php because it really is just a POST form.
<!DOCTYPE html>
<html>
<head>
<title></title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="wrapper">
<?php
include "connect.php";
$query = "SELECT * FROM members WHERE username = '".mysql_real_escape_string($_POST['username'])."' AND password = '".mysql_real_escape_string($_POST['password'])."'";
$result = mysql_query($query);
if (mysql_fetch_assoc($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
$username = $row['username'];
$password = $row['password'];
?><h3>Username - <?php echo $username; ?></h3><?php
?><h3>Password - <?php echo $password; ?></h3><?php
unset($_POST['username']);
unset($_POST['password']);
} // endwhile
} // endif
else {
?><h3>Wrong Username of Password. Try again.</h3><?php
unset($_POST['username']);
unset($_POST['password']);
}
?>
<input type="button" name="back" value="Back" onclick="location.href='index.php'">
</div>
</body>
</html>