Jump to content

redirect


ultratek

Recommended Posts

i cannot get my register page to redirect to my thankyou page using the header function:

<?php
$page_title = 'Register';
include ('./includes/header.html');

if (isset($_POST['submitted'])) {
require_once ('mysql_connect.php');
$errors = array();
if (empty($_POST['first_name'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
$fn = escape_data($_POST['first_name']);
}
if (empty($_POST['last_name'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$ln = escape_data($_POST['last_name']);
}
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
$e = escape_data($_POST['email']);
}
if (!empty($_POST['password1'])) {
if ($_POST['password1'] != $_POST['password2']) {
$errors[] = 'Your password did not match the confirmed password.';
} else {
$p = escape_data($_POST['password1']);
}
} else {
$errors[] = 'You forgot to enter your password.';
}
if (empty($errors)) {
$query = "SELECT user_id FROM users WHERE email='$e'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {
$query = "INSERT INTO users (first_name, last_name, email, password, registration_date)
VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW() )";
$result = @mysql_query ($query);
if ($result) {
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0 ,-1);
}
$url .= '/thanks.php';
header("location: $url");
exit();
} else {
echo '<h1 id="mainhead">System Error</h1>
<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>';
include ('./includes/footer.html');
exit();
}
} else {
echo '<h1 id="mainhead">Error!</h1><p class="error">The email address has already been registered.</p>';
}
} else {
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p><p><br /></p>';
}
mysql_close();
}
?>
<h2>Register</h2>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" size="20" maxlength="30" value="<?php if (isset($_POST['first_name'])) 
echo $_POST['first_name'];
?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="20" maxlength="30" value="<?php if (isset($_POST['last_name'])) 
echo $_POST['last_name'];
?>" /></p>
<p>Email: <input type="text" name="email" size="30" maxlength="40" value="<?php if (isset($_POST['email'])) 
echo $_POST['email'];
?>" /> </p>
<p>Password: <input type="password" name="password1" size="20" maxlength="20" /></p>
<p>Confirm Password: <input type="password" name="password2" size="20" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./includes/footer.html');
?>

 

what the book told me to enter in the above:

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr ($url, 0 ,-1);
}
$url .= '/thanks.php';
header("location: $url");
exit();

Link to comment
Share on other sites

it checks for a trailing slash...which i am learning about...

 

well with this script the book had me write ...  all i get is a blank page

i was wondering if there might have been some implied thought of code from the book i need to write to wrap up the header function in this script.

Link to comment
Share on other sites

it checks for a trailing slash...which i am learning about...

 

well with this script the book had me write ...  all i get is a blank page

i was wondering if there might have been some implied thought of code from the book i need to write to wrap up the header function in this script.

 

Check the URL bar. Does it contain the URL that you wish to redirect to? If so, and IF you have error reporting turned off, this could because you have a syntax error on the page that you are redirecting to. Just make sure that you aren't redirecting.

Link to comment
Share on other sites

<?php
$page_title = 'Register';
include ('./includes/header.html');

if (isset($_POST['submitted'])) {
require_once ('mysql_connect.php');
$errors = array();
if (empty($_POST['first_name'])) {
$errors[] = 'You forgot to enter your first name.';
} else {
$fn = escape_data($_POST['first_name']);
}
if (empty($_POST['last_name'])) {
$errors[] = 'You forgot to enter your last name.';
} else {
$ln = escape_data($_POST['last_name']);
}
if (empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address.';
} else {
$e = escape_data($_POST['email']);
}
if (!empty($_POST['password1'])) {
if ($_POST['password1'] != $_POST['password2']) {
$errors[] = 'Your password did not match the confirmed password.';
} else {
$p = escape_data($_POST['password1']);
}
} else {
$errors[] = 'You forgot to enter your password.';
}
if (empty($errors)) {
$query = "SELECT user_id FROM users WHERE email='$e'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {
	$query = "INSERT INTO users (first_name, last_name, email, password, registration_date)
	VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW() )";
	$result = @mysql_query ($query);
	if ($result) {
		$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
		if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
		$url = substr ($url, 0 ,-1);
		}
		$url .= '/thanks.php';
		header("location: $url");
		exit();
	} else {
	echo '<h1 id="mainhead">System Error</h1>
	<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
	echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>';
	include ('./includes/footer.html');
	exit();
	}
} else {
echo '<h1 id="mainhead">Error!</h1><p class="error">The email address has already been registered.</p>';
}
} else {
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p><p><br /></p>';
}
mysql_close();
}
?>
<h2>Register</h2>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" size="20" maxlength="30" value="<?php if (isset($_POST['first_name'])) 
echo $_POST['first_name'];
?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="20" maxlength="30" value="<?php if (isset($_POST['last_name'])) 
echo $_POST['last_name'];
?>" /></p>
<p>Email: <input type="text" name="email" size="30" maxlength="40" value="<?php if (isset($_POST['email'])) 
echo $_POST['email'];
?>" /> </p>
<p>Password: <input type="password" name="password1" size="20" maxlength="20" /></p>
<p>Confirm Password: <input type="password" name="password2" size="20" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./includes/footer.html');
?>

Link to comment
Share on other sites

More like:

 

<?php
$page_title = 'Register';
include ('./includes/header.html');

if (isset($_POST['submitted'])) {
require_once ('mysql_connect.php');
$errors = array();
if (empty($_POST['first_name'])) {
	$errors[] = 'You forgot to enter your first name.';
} else {
	$fn = escape_data($_POST['first_name']);
}
if (empty($_POST['last_name'])) {
	$errors[] = 'You forgot to enter your last name.';
} else {
	$ln = escape_data($_POST['last_name']);
}
if (empty($_POST['email'])) {
	$errors[] = 'You forgot to enter your email address.';
} else {
	$e = escape_data($_POST['email']);
}
if (!empty($_POST['password1'])) {
	if ($_POST['password1'] != $_POST['password2']) {
		$errors[] = 'Your password did not match the confirmed password.';
	} else {
		$p = escape_data($_POST['password1']);
	}
} else {
	$errors[] = 'You forgot to enter your password.';
}
if (empty($errors)) {
	$query = "SELECT user_id FROM users WHERE email='$e'";
	$result = mysql_query($query);
	if (mysql_num_rows($result) == 0) {
		$query = "INSERT INTO users (first_name, last_name, email, password, registration_date)
		VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW() )";
		$result = @mysql_query ($query);
		if ($result) {
			$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
			if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
				$url = substr ($url, 0 ,-1);
			}
			$url .= '/thanks.php';
			header("location: $url");
			exit();
		} else {
			echo '<h1 id="mainhead">System Error</h1>
			<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>';
			echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>';
			include ('./includes/footer.html');
			exit();
		}
	} else {
		echo '<h1 id="mainhead">Error!</h1><p class="error">The email address has already been registered.</p>';
	}
} else {
	echo '<h1 id="mainhead">Error!</h1>
	<p class="error">The following error(s) occurred:<br />';
	foreach ($errors as $msg) {
		echo " - $msg<br />\n";
	}
	echo '</p><p>Please try again.</p><p><br /></p>';
}
mysql_close();
}
?>
<h2>Register</h2>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" size="20" maxlength="30" value="<?php if (isset($_POST['first_name'])) 
echo $_POST['first_name'];
?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="20" maxlength="30" value="<?php if (isset($_POST['last_name'])) 
echo $_POST['last_name'];
?>" /></p>
<p>Email: <input type="text" name="email" size="30" maxlength="40" value="<?php if (isset($_POST['email'])) 
echo $_POST['email'];
?>" /> </p>
<p>Password: <input type="password" name="password1" size="20" maxlength="20" /></p>
<p>Confirm Password: <input type="password" name="password2" size="20" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./includes/footer.html');
?>

 

But it still looks kinda messy.

Link to comment
Share on other sites

ok now i relized i was sending the page title and the include to the browser before the header function...

so i am carefully reviewing my script against the book and i am getting this error when i test it:

<?php
if (isset($_POST['submitted'])) {
require_once ('mysql_connect.php');
$errors = array();
if (empty($_POST['first_name'])) {
	$errors[] = 'You forgot to enter your first name.';
} else {
$fn = escape_data($_POST['first_name']);
}
if (empty($_POST['last_name'])) {
	$errors[] = 'You forgot to enter your last name.';
} else {
$ln = escape_data($_POST['last_name']);
}
if (empty($_POST['email'])) {
	$errors[] = 'You forgot to enter your email address.';
} else {
$e = escape_data($_POST['email']);
}
if (!empty($_POST['password1'])) {
if ($_POST['password1'] != $_POST['password2']) {
	$errors[] = 'Your password did not match the confirmed password.';
} else {
$p = escape_data($_POST['password1']);
}
} else {
	$errors[] = 'You forgot to enter your password.';
}
if (empty($errors)) {
$query = "SELECT user_id FROM users WHERE email='$e'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) {
	$query = "INSERT INTO users (first_name, last_name, email, password, registration_date)
	VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW() )";
	$result = @mysql_query ($query);
	if ($result) {
		$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
		if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
		$url = substr ($url, 0 ,-1);
		}
		$url .= '/thanks.php';
		header("location: $url");
		exit();
	} else {
	$errors[] = 'You could not be registered due to a system error. We apologize for any inconvenience.';
	$errors[] = mysql_error() . '<br /><br />Query: ' . $query;
	}
} else {
	$errors[] = 'The email address has already been registered.';
}
mysql_close();
} else {
$errors = NULL;
}
$page_title = 'Register';
include ('./includes/header.html');
if (!empty($errors)) {
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) {
echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p>';
}
?>
<h2>Register</h2>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" size="20" maxlength="30" value="<?php if (isset($_POST['first_name'])) 
echo $_POST['first_name'];
?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="20" maxlength="30" value="<?php if (isset($_POST['last_name'])) 
echo $_POST['last_name'];
?>" /></p>
<p>Email: <input type="text" name="email" size="30" maxlength="40" value="<?php if (isset($_POST['email'])) 
echo $_POST['email'];
?>" /> </p>
<p>Password: <input type="password" name="password1" size="20" maxlength="20" /></p>
<p>Confirm Password: <input type="password" name="password2" size="20" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./includes/footer.html');
?>

 

error:

Parse error: syntax error, unexpected $end in \\boswinfs02\home\users\web\b1623\ez.ultratek\practice\register.php on line 84

Link to comment
Share on other sites

You've missed out on a curly bracket somewhere.

 

Try:

<?php
if (isset($_POST['submitted'])) 
{
require_once ('mysql_connect.php');
$errors = array();
if (empty($_POST['first_name'])) 
{
	$errors[] = 'You forgot to enter your first name.';
} 
else 
{
	$fn = escape_data($_POST['first_name']);
}
if (empty($_POST['last_name'])) 
{
	$errors[] = 'You forgot to enter your last name.';
} 
else 
{
	$ln = escape_data($_POST['last_name']);
}
if (empty($_POST['email'])) {
	$errors[] = 'You forgot to enter your email address.';
} 
else 
{
	$e = escape_data($_POST['email']);
}
if (!empty($_POST['password1'])) 
{
	if ($_POST['password1'] != $_POST['password2']) 
	{
		$errors[] = 'Your password did not match the confirmed password.';
	} 
	else 
	{
	$p = escape_data($_POST['password1']);
	}
} 	
else 
{
	$errors[] = 'You forgot to enter your password.';
}
}

if (empty($errors)) 
{
$query = "SELECT user_id FROM users WHERE email='$e'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) 
{
	$query = "INSERT INTO users (first_name, last_name, email, password, registration_date)
	VALUES ('$fn', '$ln', '$e', SHA('$p'), NOW() )";
	$result = @mysql_query ($query);
	if ($result) 
	{
		$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
		if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) 
		{
		$url = substr ($url, 0 ,-1);
		}
		$url .= '/thanks.php';
		header("location: $url");
		exit();
	} 
	else 
	{
		$errors[] = 'You could not be registered due to a system error. We apologize for any inconvenience.';
		$errors[] = mysql_error() . '<br /><br />Query: ' . $query;
	}
} 
else 
{
	$errors[] = 'The email address has already been registered.';
}
mysql_close();
} 
else {
$errors = NULL;
}
$page_title = 'Register';
include ('./includes/header.html');
if (!empty($errors)) 
{
echo '<h1 id="mainhead">Error!</h1>
<p class="error">The following error(s) occurred:<br />';
foreach ($errors as $msg) 
{
	echo " - $msg<br />\n";
}
echo '</p><p>Please try again.</p>';
}
?>
<h2>Register</h2>
<form action="register.php" method="post">
<p>First Name: <input type="text" name="first_name" size="20" maxlength="30" value="<?php if (isset($_POST['first_name'])) 
echo $_POST['first_name'];
?>" /></p>
<p>Last Name: <input type="text" name="last_name" size="20" maxlength="30" value="<?php if (isset($_POST['last_name'])) 
echo $_POST['last_name'];
?>" /></p>
<p>Email: <input type="text" name="email" size="30" maxlength="40" value="<?php if (isset($_POST['email'])) 
echo $_POST['email'];
?>" /> </p>
<p>Password: <input type="password" name="password1" size="20" maxlength="20" /></p>
<p>Confirm Password: <input type="password" name="password2" size="20" maxlength="20" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>
<?php
include ('./includes/footer.html');
?>

Link to comment
Share on other sites

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.