Database login doesn't seem to be working when password is correct
just wondering if someone can look at this code and tell me where I am
making my mistake. What the code is supposed to do is check username and
password with a database and then run an if statement to either allow the
user to view the page or just show them a "Please login" message. At this
point it is only returning the false values even if the passwords are ==.
I know I can pick up code for this on the internet, but I want to figure
out where my logic (only in my head) is going wrong. I also know I haven't
sanitized the data, but this is just a tutorial for grade 10 students just
learning HTML and CSS with a little bit of PHP. I will get to that
protecting data later. (one concept at a time)
Thanks for the help!
<?php
// connects to server
include('includes/connect2.php');
// sets post to variables, don't know if this is needed
$user=$_POST[username];
$pass=$_POST[password];
?>
<?php
// query to find information in database
$result = mysqli_query($con, "SELECT * FROM social_register WHERE
Login='$user'" );
if ($pass == $result['Password']){?>
<div id="container">
<div id="banner">
The social Site
<div id="site_logo">
<img src="images/logo_thumb.gif" />
<?php
while($row = mysqli_fetch_array($result))
{
echo $row['First_Name'] . " " . $row['Last_Name'];
echo "<br>";
}
mysqli_close($con);
?>
</div>
</div>
<div id="person">
<h1>Welcome to your test web site</h1>
</div>
</div>
<?php
}
// else part of code to display result if user is not logged in
else
{
?>
<div id="container">
<div id="banner">
The social Site
<div id="site_logo">
<img src="images/logo_thumb.gif" />
</div>
</div>
<div id="person">
<h1>You have not loged into the site, please login.</h1>
</div>
<?php
}
?>
No comments:
Post a Comment