php? Posted January 2, 2008 Share Posted January 2, 2008 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'; } } Quote Link to comment https://forums.phpfreaks.com/topic/84068-solved-what-is-happening/ Share on other sites More sharing options...
priti Posted January 2, 2008 Share Posted January 2, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/84068-solved-what-is-happening/#findComment-427939 Share on other sites More sharing options...
php? Posted January 2, 2008 Author Share Posted January 2, 2008 Yes it did, thanks a lot Quote Link to comment https://forums.phpfreaks.com/topic/84068-solved-what-is-happening/#findComment-427943 Share on other sites More sharing options...
priti Posted January 2, 2008 Share Posted January 2, 2008 your most welcome Quote Link to comment https://forums.phpfreaks.com/topic/84068-solved-what-is-happening/#findComment-427968 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.