Building a registration/login system and errors
I'm trying to build a registration and login system, so that I can password protect certain pages.
There will be different levels of users. If you are not registered, you can only access generic pages, if you are registered and logged in, you can see some pages, and if you have a subscription, you can access all pages. At least that is the intention.
I'm currently at step one and try to follow the tutorial of http://www.easykiss123.com/easy-setup-of-login-registration-and-password-protected-areas-on-your-website/
While the tutorial is quite nice, it contains a number of errors of things that just do not work as described. One is the use of 'mysqli_...' commands which need to be replaced by 'mysql_..' commands. Notice without the letter i.
Another problem in the tutorial is that one of the files contains a php function:
date_default_timezone_set ('Europe/London') call that can only be commented out.
Now with these adjustments things are getting underway, but using this code:
<?php # Script 16.8 - login.php
// This is the login page for the site.
require_once ('includes/config.inc.php');
$page_title = 'Login';
include ('includes/header.php');
if (isset($_POST['submitted'])) {
require_once (MYSQL);
// Validate the email address:
if (!empty($_POST['email'])) {
$e = mysql_real_escape_string ($dbc, $_POST['email']);
} else {
$e = FALSE;
echo '<p class="error">You forgot to enter your email address!</p>';
}
// Validate the password:
if (!empty($_POST['pass'])) {
$p = mysql_real_escape_string ($dbc, $_POST['pass']);
} else {
$p = FALSE;
echo '<p class="error">You forgot to enter your password!</p>';
}
if ($e && $p) { // If everything's OK.
// Query the database:
$q = "SELECT user_id, first_name, user_level FROM users WHERE (email='$e' AND pass=SHA1('$p')) AND active IS NULL";
$r = mysql_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysql_error($dbc));
if (@mysql_num_rows($r) == 1) { // A match was made.
// Register the values & redirect:
$_SESSION = mysql_fetch_array ($r, MYSQL_ASSOC);
mysql_free_result($r);
mysql_close($dbc);
$url = BASE_URL . 'index.php'; // Define the URL:
ob_end_clean(); // Delete the buffer.
header("Location: $url");
exit(); // Quit the script.
} else { // No match was made.
echo '<p class="error">Either the email address and password entered do not match those on file or you have not yet activated your account.</p>';
}
} else { // If everything wasn't OK.
echo '<p class="error">Please try again.</p>';
}
mysql_close($dbc);
} // End of SUBMIT conditional.
?>
the two bold lines give the following error messages:
<p>An error occurred in script '/homepages/3/d173460647/
htdocs/ppbm6/Login/login.php' on line 13: mysql_real_escape_string() expects parameter 1 to be string, resource given
<br />Date/Time: 11-19-2011 05:40:32
<p>An error occurred in script '/homepages/3/d173460647/
htdocs/ppbm6/Login/login.php' on line 21: mysql_real_escape_string() expects parameter 1 to be string, resource given
<br />Date/Time: 11-19-2011 05:40:34
What did I do wrong here and how can I correct it?
