Forum Moderators: coopster
My page does everything I want it to do, but, redirect the user to the page I list in the "header". Can someone tell me if the "Header" is in the right place. I know the header has to come before any output to the browser(echo, print..etc). Help...smile
Thanks In Advance
Senmar
^^^^^^^^^^^^^^^^^^^
<?php
$page_title = "Register";
if (isset($_POST['submit'])) { // Handle the form.
// Create a function for escaping the data.function escape_data ($data) {
global $dbc; // Need the connection.
if (ini_get('magic_quotes_gpc')) {
$data = stripslashes($data);
}
return mysql_real_escape_string($data, $dbc);
} // End of function.
$message = NULL; // Create an empty new variable.
// Check for a username.
if (empty($_POST['username'])) {
$u = FALSE;
$message .= '<p>You forgot to enter your username!</p>';
} else {
$u = $_POST['username'];
}
//Check for a first name.
if (empty($_POST['first_name'])) {
$fn = FALSE;
$message .= '<p>You forgot to enter your first name!</p>';
} else {
$fn = $_POST['first_name'];
}
// Check for a last name.
if (empty($_POST['last_name'])) {
$ln = FALSE;
$message .= '<p>You forgot to enter your last name!</p>';
} else {
$ln = $_POST['last_name'];
}
// Check for an email address.
if (empty($_POST['email'])) {
$e = FALSE;
$message .= '<p>You forgot to enter your email address!</p>';
} else {
$e = $_POST['email'];
}
// Check for a password and match against the confirmed password.
if (empty($_POST['password1'])) {
$p = FALSE;
$message .= '<p>You forgot to enter your password!</p>';
} else {
if ($_POST['password1'] == $_POST['password2']) {
$p = $_POST['password1'];
} else {
$p = FALSE;
$message .= '<p>Your password did not match the confirmed password!</p>';
}
}
if ($u && $fn && $ln && $e && $p) {
// If everything's OK.
// Register the user in the database.
require_once (''); // Connect to the db.
// Make the query.
$query = "INSERT INTO people (username, first_name, last_name, email, password, registration_date) VALUES ('$u', '$fn', '$ln', '$e', MD5('$p'), NOW() )";
$result = mysql_query ($query); // Run the query.
if ($result) { // If it ran OK.
// Send an email, if desired.
$body = "Thank you for registering with our!\n\nYour username is '{$_POST['username']}' and your password is '{$_POST['password1']}'.\n\nSincerely,\n\nWebSite Coordinator";
mail ($_POST['email'], 'Thank you for registering!', $body, 'From: senamo@aol.com');
header ("Location: login.php");
echo '<p>You are now registered. An email has been sent to your email address confirming the information.</p>';
exit(); // Quit the script.
} else {
$message = '<p>You could not be registered due to a system error. We apologize for any inconvenience.</p><p>' . mysql_error() . '</p>';
}
} else {
mysql_close(); // Close the database connection.
$message .= '<p>Please try again.</p>';
}
} // End of the main Submit conditional.
// Print the error message if there is one.
if (isset($message)) {
echo '<font color="red">', $message, '</font>';
}
?>
<html>
<head>
<title></title>
</head>
<body>
<div id="header">
<h2>Welcome</h2>
<h4>DECEMBER 10-12, 2005</h4>
<h4> To access the important documents in this database, please register below.</h4>
</div>
<div id="container">
<div id="left">
<div class="form">
<form method="POST" action="welcome.php">
<tr>
<td><b>Enter Username:</b> <input type="text" name="username" size="20"></td>
<br/>
<td><b>Enter Password:</b> <input type="password" name="password" size="20"></td>
<br/>
<td><input type="submit" value="Submit"></td>
<td><input type="reset"></td>
</tr>
</form>
</div>
<div class="button"><a href="index.htm">BACK TO HOME PAGE</a>
</div></div>
<div id="content">
<p><form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<fieldset><legend><b>Please register below to gain access to the ""</b></legend>
<p><b>User Name:</b> <input type="text" name="username" size="20" maxlength="25" value="<?php if (isset($_POST['username'])) echo $_POST['username'];?>" /></p>
<p><b>First Name:</b> <input type="text" name="first_name" size="20" maxlength="25" value="<?php if (isset($_POST['first_name'])) echo $_POST['first_name'];?>" /></p>
<p><b>Last Name:</b> <input type="text" name="last_name" size="30" maxlength="30" value="<?php if (isset($_POST['last_name'])) echo $_POST['last_name'];?>" /></p>
<p><b>Email Address:</b> <input type="text" name="email" size="30" maxlength="40" value="<?php if (isset($_POST['email'])) echo $_POST['email'];?>" /> </p>
<p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="32" /></p>
<p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" /></p>
</fieldset>
</p>
<div align="center"><input type="submit" name="submit" value="Register" /></div>
</form>
</div>
</div>
<div id="footer">
<p>© 2005 by ME</p>
</div>
</body>
</html>
header ("Location: http://www.example.com/file.ext");
After the email is sent to tell the user that he/she is registered, I want to redirect them to the login page. There they can login to the members'section with their new password. The browser seems to stay on the email message sent to the new member, and doesn't redirect to the "Login/Logon" page...
Thanks,
Senmar
You always come through...
Use the "Absolute Header:
header ("Location: [mysite.org...]
Thanks Again,
SenMar