Login page
| From: | Erik Gjertsen | Date: | Thu, 06 May 2004 10:42:48 +0000 |
| Subject: | Login page | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-185507@lists.php.net to get a copy of this message | ||
I have made a login page but I got an error on line 1.....
Can some one please help me to solve the problem
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>LoggInn</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
# login.php
if (isset($_POST['submit'])) { // Handel the form.
require_once('../../../Connections/innlogging.php');
mysql_select_db($database_innlogging, $innlogging);
$query_logginn = "SELECT usrid, username, password1 FROM users";
$logginn = mysql_query($query_logginn, $innlogging) or die(mysql_error());
$row_logginn = mysql_fetch_assoc($logginn);
$totalRows_logginn = mysql_num_rows($logginn);
// Crating a function for escaping the data.
function escape_data ($data) {
global $dbc; //meed the connection
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
1........ return mysql_real_escape_string($data, $dbc);
} // end of function
$message = NULL; // Create an enpty new variable
// Check for a username
if (empty($_POST['username'])) {
$username = FALSE;
$message .= '<p>You forgot to enter your username!</p>';
} else {
$username = escape_data($_POST['username']);
}
// Check for a Password
if (empty($_POST['password1'])) {
$password1 = FALSE;
$message .= '<p>You forgot to enter your password!</p>';
} else {
$password1 = escape_data($_POST['password1']);
}
if ($username && $password1) { //if everything's ok.
//Retrieve the user_id an name for that username and password combination.
$query = "SELECT usrid name FROM users WHERE username='$username' AND
password1=PASSWORD('$password1')";
$result = @mysql_query ($query); //Run the query
$row = mysql_fetch_array ($result, MYSQL_NUM); //Return a record, if
applicable.
if ($row) { //A record was pulled from the database.
//Set the cookies & redirect.
setcookie ('name', $row[1]);
setcookie ('usrid', $row[1]);
header ("Location: http://" .
$_SERVER['HTTP_HOST'] .
dirname($_SERVER['PHP_SELF']) . "/Loggedin.php");
exit(); //Quit the script
} else { // No record matched the query.
$message = '<p>The username and password entered do not match on
file.</p>';
}
mysql_close(); // Close the databaseconection.
} else {
$message = '<p>Please try again.</p>';
}
} // End of themail submitconditional.
//Print the error message if ther is one
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>"
method="post">
<fieldset><legend>Enter your information in the form below:</legend>
<p><b>User Name:</b> <input type="text" name="username"
size="10"
maxlength="20" value="<?php if
(isset($_POST['username'])) echo $_POST['username']; ?>" /></p>
<p><b>Password:</b> <input type="password1"
name="password1" size="20"
maxlength="20" /></p>
<div align="center"><input type="submit" name="submit"
value="Login"
/></div>
</fieldset>
</form>
</body>
</html>
Thanks
Erik Gjertsen