Jump to content

[SOLVED] What is happening


php?

Recommended Posts

What is happening within this code?

if(mysql_num_rows($query) == 1)
		{
			$row = mysql_fetch_assoc($query);
			if($row['Active'] == 1)
			{
				session_start();
				$_SESSION['user_id'] = $row['ID'];
				$_SESSION['logged_in'] = TRUE;
				header("Location: members.php");
			}
			else {
				$error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';
			}
		}
		else {		
			$error = 'Login failed !';		
		}
	}
	else {
		$error = 'Please use both your username and password to access your account';
	}
}

Link to comment
https://forums.phpfreaks.com/topic/84068-solved-what-is-happening/
Share on other sites

Hi,

 

It 's very simple If and else ...

 

1.mysql_num_rows return number of records fetched form your query.

So

 

2.if number of record == 1 then

  row = mysql_fetch_assoc($query); script tries to fetch the data from the recordset  after that

 

3.

if($row['Active'] == 1)

{

session_start();

$_SESSION['user_id'] = $row['ID'];

$_SESSION['logged_in'] = TRUE;

header("Location: members.php");

}

else {

          $error = 'Your membership was not activated. Please open the email that we sent and click on the activation link';

}

 

4. Above snippet explain if you are active member then user's info is inserted in $_SESSION and redirected to members.php page BUT if you active state is not 1 then message will get display ($error).

 

5. IF mysql_num_rows($query) is not equals 1

  then $error = 'Login failed !';

 

//For this else there is one missing IF condition .In your code provided that is missing.

else {

$error = 'Please use both your username and password to access your account';

}

 

Hope it gives a fair amount of knowledge to you to understand what this script is doing.

 

Regards

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.