1

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.        
}
2

1 Answer 1

1
if($row['paid'] == 0);{

Get rid of that semicolon in there:

if($row['paid'] == 0){
Sign up to request clarification or add additional context in comments.

1 Comment

Nice one! half the day wasted over a stray semicolon! tried to vote you up but I dont have enough reputation!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.