Jump to content

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

 

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.