Reputation: 27
I am new to php and mysql.The following code is from a login page. I am trying to use a boolean(tinyint) value in a mysql database called users. If the value of the field 'paid' is 0 I want to send users to my pay.php page, if value is 1 and login details are correct i want to send users to index.php. However the code sends users to pay.php whether value in database is 0 or 1. Any help would be greatly appreciated!
$query = mysql_query("SELECT * FROM `users` WHERE username = '$username' AND password = '$password'") or die (mysql_error()); // mySQL query
$r = mysql_num_rows($q); // Checks to see if anything is in the db.
$row = mysql_fetch_array($query);
if($row['paid'] == 0);{ //NOT WORKING!!!
header ("location:pay.php");// go to pay.php
exit( );// Stops the rest of the script.
}
if ($r == 1) { // There is something in the db. The username/password match up.
$_SESSION['logged'] = 1; // Sets the session.
header ("location:index.php");// go to index.php
}
else { // Invalid username/password.
exit("Incorrect username/password!"); // Stops the script with an error message.
}
Upvotes: 1
Views: 955
Reputation: 799
if($row['paid'] == 0);{
Get rid of that semicolon in there:
if($row['paid'] == 0){
Upvotes: 1