Reputation: 737
My code wont echo out to me, yet I believe it should be working. I'm trying to have it tell me that if it finds a row in my database, to match it and tell me im logged in, or if it finds no rows, then to echo out that the combo is invalid. Regardless, its not echo'ing out a single thing? I'm very new to this, and I just can not seem to figure it out. Work your magic please guys?
Note: All of the databases referred to in the query do exist, and it is connected to that database as well.
Thanks!
<?php
if (isset($_POST['username'])&&isset($_POST['password']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$password_hash = md5($password);
if (!empty($username)&&!empty($password))
{
$query = "SELECT `id` FROM `users` WHERE `username`='$username' AND `password`='$password_hash'";
if ($query_run = mysql_query($query))
{
$query_num_rows = mysql_num_rows($query_run);
if ($query_num_rows==0)
{
echo 'Invalid username password combination';
}
else
{
echo 'Ok.';
}
}
}
}
?>
<form action="<?php echo $current_file; ?>" method="POST">
Username: <input type="text" name="username" class="login">
Password: <input type="password" name="password" class="login">
<input type="submit" value="Login">
</form>
Upvotes: 0
Views: 107
Reputation: 1982
You have a lot of else without a respective else statement that prints something out. If one of this if condition is false you get no outpu. try:
if (isset($_POST['username'])&&isset($_POST['password']))
{
$username = $_POST['username'];
$password = $_POST['password'];
$password_hash = md5($password);
if (!empty($username)&&!empty($password))
{
$query = "SELECT `id` FROM `users` WHERE `username`='$username' AND `password`='$password_hash'";
if ($query_run = mysql_query($query))
{
$query_num_rows = mysql_num_rows($query_run);
if ($query_num_rows==0)
{
echo 'Invalid username password combination';
}
else
{
echo 'Ok.';
}
}
else echo 'query exeution returned false';
}
else echo 'empty username or password';
}
else echo 'not isset username or pwd';
Finally if you get no output even with this else stataments then watch into the log if any fatal error appears and blocks the execution before any output is print!
Upvotes: 0
Reputation: 2476
You aren't connecting to a database. You need to add something like this:
$link = mysql_connect("localhost", "mysql_user", "mysql_password");
Upvotes: 1