Jump to content

[SOLVED] if statement always returning false


PC Nerd

Recommended Posts

hi guys.

 

i have a login script ( yes the same one still).  and now ithe if, is always returning false

 

 

 

	$DB_Login_SQL = "SELECT User_Name, `Password`, User_ID, Account_Type FROM general_stats WHERE User_Name = '".$User_Name."'";
	$Login_Query = mysqli_query($DB_Server, $DB_Login_SQL);
	echo mysqli_error($DB_Server);

	if($Login_Query != 0 && !empty($Login_Query)) {

		$DB_Login = mysqli_fetch_array($Login_Query);

		echo $DB_Login["User_ID"];
		echo $DB_Login["User_Name"];
		echo $DB_Login["Password"];


		if($Game_Status['Game_Status'] != 'Online') {
			if($DB_Login['Account_Type'] != 'Moderator' && $DB_Login['Account_Type'] != 'Administration') {

				echo $DB_Login['Account_Type'];

				#echo "<script  language = 'JavaScript' type = 'text/javascript'>\n";
				#echo "window.location = 'redirection_locaiton';\n";
				#echo "<script>";
			}
		}

			if($password == $DB_Login['Password']) {

				require("inc_files/B_A-Login.inc");

				echo "<script  language = 'JavaScript' type = 'text/javascript'>\n";
				echo "window.location = 'file.php?Login_ID=".$Login['Login_ID']."&User_ID=".$DB_Login['User_ID']."&User_Name=".$DB_Login['User_Name']."'\n";
				echo "</script>";


			}

			else {
			$Error = True;
			$Error4 = True;
			}



	}
	else {
	$Error = True;
	$Error3 = True;
	}

 

Its the if, returning error 4.  ive noticed that when the $DB_Login values are echoed near the begining, they dont return anything.  however its wierd, becauase the fetech_array statement, doesnt return any error either.

 

I know its some thing wiht the script, becauase when i use mysqli_error later on, it doesnt retuen anything,  but this is always returning false, therefore, the script never logs you in.

Link to comment
Share on other sites

$Password is set, like $User_Name etc. right at the begining of the script:

 

$Password = $_POST['Password'];

 

 

etc.

 

and i know its passing properly, becauase the two conditions befor this if...... test if its emtpy, and if the image validate is correct.

 

 

thanks

Link to comment
Share on other sites

Remember that PHP is case sensitive, from the line you posted above this is what your if statement should read.

 

<?php
if($Password == $DB_Login['Password']) { // note the capitol P for $Password

Link to comment
Share on other sites

Well a shot in the dark, could it be that your query is returning more than one user? I noticed there is no LIMIT 1 set. Maybe the wrong user is being pulled out whom has a different password?

 

Also maybe try to trim the post data before assigning it to value, maybe an extra whitespace is throwing it off?

 

Other than that I am out of ideas...

Link to comment
Share on other sites

ok,, here is the full code:

 

i know that the SQL is going to be unique, becauase i already have a script that ensures that a username is unique.... so therefore the pasword may be the same for some users, but its the different users. etc, so its not that, however i now know that the query isnt returning a password field, so its the query not working.

 

$Game_Status = "Testing";

 

 

 

$username = $_POST['User_Name'];

$password = $_POST['Password'];

$valid = $_POST['Valid'];

 

#echo "Username: {$username}<br>Password: {$password}<br>Valid: {$valid}<br><br>"; //echo out the values to see if they are being sent.

 

$Error = "";

$Error1 = "";

$Error2 = "";

$Error3 = "";

$Error4 = "";

 

if($username != "" && $password != "" && $valid != "") {

require('inc_files/Login_Pics.inc');

$img = "B_A-Login_".$_POST['IMG_Valid'];

 

$Image_Validate = $IMAGES["$img"];

 

if($_POST['Valid'] == $Image_Validate) {

 

$DB_Login_SQL = "SELECT User_Name, `Password`, User_ID, Account_Type FROM general_stats WHERE User_Name = '".$User_Name."' LIMIT 1";

$Login_Query = mysqli_query($DB_Server, $DB_Login_SQL);

echo mysqli_error($DB_Server);

 

if($Login_Query != 0 && !empty($Login_Query)) {

 

$DB_Login = mysqli_fetch_array($Login_Query);

 

echo $DB_Login["User_ID"];

echo $DB_Login["User_Name"];

echo $DB_Login["Password"];

 

 

if($Game_Status['Game_Status'] != 'Online') {

if($DB_Login['Account_Type'] != 'Moderator' && $DB_Login['Account_Type'] != 'Administration') {

 

echo $DB_Login['Account_Type'];

 

#echo "<script  language = 'JavaScript' type = 'text/javascript'>\n";

#echo "window.location = 'file2.php';\n";

#echo "<script>";

}

}

 

if($password == $DB_Login['Password']) {

 

require("inc_files/include.inc");

 

echo "<script  language = 'JavaScript' type = 'text/javascript'>\n";

echo "window.location = 'file.php?Login_ID=".$Login['Login_ID']."&User_ID=".$DB_Login['User_ID']."&User_Name=".$DB_Login['User_Name']."'\n";

echo "</script>";

 

 

 

}

 

else {

$Error = True;

$Error4 = True;

}

 

 

 

}

else {

$Error = True;

$Error3 = True;

}

}

else {

$Error = True;

$Error2 = True;

}

}

else {

$Error = True;

$Error1 = True;

}

 

 

so i think that the query isnt actually returning anythihng......

 

how do i echo every set variable / array in a poage.  i know ive done it before.  i want to see it the query is returning a mysqli_object, or if its returning a Boolean fail value.

 

could someone help me to do this.

 

thanks for all your help

Link to comment
Share on other sites

you can use the following line to have your script echo all currently registered variables and then die:

 

exit('<pre>'.print_r(get_defined_vars(), TRUE));

 

be careful with this on a production server, as it sometimes gives away some very sensitive information.

Link to comment
Share on other sites

Your making this allot more difficult then it needs to be. Check your username / password combination is valid in the query. eg;

 

$DB_Login_SQL = "SELECT User_Name, `Password`, User_ID, Account_Type FROM general_stats WHERE User_Name = '$User_Name' && Password = '$password' LIMIT 1";

 

If this fails to retrieve a result you know the combination was incorrect.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.