Jump to content

wont go into if()


0perator

Recommended Posts

<?php
 $username = $_POST['username'];
 $password = $_POST['password'];
 $md5pass = md5($password);
 $login_check = mysql_query("SELECT * FROM students WHERE `Username` = '$username' AND `Password` = '$md5pass'");
 $login_rows = mysql_num_rows($login_check);
 if($login_rows == 0){
 $login_check_t = mysql_query("SELECT * FROM teachers WHERE `Username` = '$username' AND `Password` = '$md5pass'");
 $login_rows_t = mysql_num_rows($login_check_t);
 if($login_rows_t == 0) die('Login failed</body></html>');
 }
 elseif($login_rows_t >= 1){
 $login_array_t = mysql_fetch_array($login_check_t);
 echo 'LOL LOL LOL LOL';
 echo 'Welcome '.$login_array_t['Name'];
 }
 elseif($login_rows >= 1){
 $login_array = mysql_fetch_array($login_check);
 echo 'Welcome '.$login_array['Name'];
 }
 else{
 echo 'some sort of failure in the system';
 }
 ?>

 

it wont go into the LOL LOL LOL LOL section.. no matter what, it does not echo "some sort of failure in the system either". the student login works fine..

Link to comment
Share on other sites

Never mind that AGAIN! XD lol. You making it die at one spot even if it is correct or wrong.

 

$username = $_POST['username'];
    $password = $_POST['password'];
    $md5pass = md5($password);
    $login_check = mysql_query("SELECT * FROM students WHERE `Username` = '$username' AND `Password` = '$md5pass'");
    $login_rows = mysql_num_rows($login_check);
    if($login_rows == 0){
    $login_check_t = mysql_query("SELECT * FROM teachers WHERE `Username` = '$username' AND `Password` = '$md5pass'");
    $login_rows_t = mysql_num_rows($login_check_t);
//This if will always make your page DIE. 
//Add OR die 
    if($login_rows_t == 0) or die('Login failed</body></html>');

    }

 

I hope this fixes your problem.

Link to comment
Share on other sites

it wont go into the LOL LOL LOL LOL section.. no matter what, it does not echo "some sort of failure in the system either". the student login works fine..

No it won't, because you're not defining $login_rows_t before the start of the if statement, so it isn't set and the condition $login_rows_t >= 1 can never be true
Link to comment
Share on other sites

Lets do a bit of code cleanup...

 

<?php
$username = $_POST['username'];
$password = $_POST['password'];
$md5pass = md5($password);

// check if user is a student
$student_result = mysql_query("SELECT * FROM students WHERE `Username` = '$username' AND `Password` = '$md5pass'");
$student_num_rows = mysql_num_rows($student_result);

if ($student_num_rows == 0) {

// check and see if user is a teacher
$teacher_result = mysql_query("SELECT * FROM teachers WHERE `Username` = '$username' AND `Password` = '$md5pass'");
$teacher_num_rows = mysql_num_rows($teacher_result);

if ($teacher_num_rows == 0) {

	// no student or teacher found with given username and password
	die('Login failed');

} else if ($teacher_num_rows >= 1) {

	// print teacher welcome message
	$teacher = mysql_fetch_assoc($teacher_result);
	echo 'LOL LOL LOL LOL';
	echo 'Welcome '.$teacher['Name'];
}

} else if ($student_num_rows >= 1) {

// print student welcome message
$student = mysql_fetch_assoc($student_result);
echo 'Welcome '.$student['Name'];

} else {
echo 'some sort of failure in the system';
}
?>

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.