PC Nerd Posted May 17, 2007 Share Posted May 17, 2007 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 https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/ Share on other sites More sharing options...
per1os Posted May 17, 2007 Share Posted May 17, 2007 Where is $password being set? Link to comment https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-255908 Share on other sites More sharing options...
PC Nerd Posted May 17, 2007 Author Share Posted May 17, 2007 $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 https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-255915 Share on other sites More sharing options...
per1os Posted May 17, 2007 Share Posted May 17, 2007 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 https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-255919 Share on other sites More sharing options...
PC Nerd Posted May 17, 2007 Author Share Posted May 17, 2007 ive checked case, stilln ot working Link to comment https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-255932 Share on other sites More sharing options...
per1os Posted May 17, 2007 Share Posted May 17, 2007 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 https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-255940 Share on other sites More sharing options...
PC Nerd Posted May 17, 2007 Author Share Posted May 17, 2007 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 https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-255947 Share on other sites More sharing options...
akitchin Posted May 17, 2007 Share Posted May 17, 2007 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 https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-255965 Share on other sites More sharing options...
trq Posted May 18, 2007 Share Posted May 18, 2007 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 https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-255981 Share on other sites More sharing options...
PC Nerd Posted May 18, 2007 Author Share Posted May 18, 2007 um, makes no difference, im still not getting no password from the database thanks, anything else i should try? Link to comment https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-256132 Share on other sites More sharing options...
jitesh Posted May 18, 2007 Share Posted May 18, 2007 Debug like this. echo $password; echo "<br>"; echo $DB_Login['Password']; if($password == $DB_Login['Password']) { echo "come to if"; }else{ echo "come to else"; } Link to comment https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-256157 Share on other sites More sharing options...
PC Nerd Posted May 18, 2007 Author Share Posted May 18, 2007 ok, i only get $password, and bot the database retreival one. also, it gets to the sle, and passes the if. thanks Link to comment https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-256168 Share on other sites More sharing options...
PC Nerd Posted May 19, 2007 Author Share Posted May 19, 2007 any ideas? thanks Link to comment https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-256792 Share on other sites More sharing options...
PC Nerd Posted May 20, 2007 Author Share Posted May 20, 2007 bump Link to comment https://forums.phpfreaks.com/topic/51907-solved-if-statement-always-returning-false/#findComment-257492 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.