Jump to content

Recommended Posts

cleaned up the code....i cannot figure out why lines 61 through 72 do not work for me to redirect to my thanks page...in the same directory....i get a blank page after i submit the register.php:

<?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');
?>

 

section:

$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
https://forums.phpfreaks.com/topic/134045-solved-redirectcont/
Share on other sites

<?php

error_reporting(E_ALL) ; ini_set('display_errors','1');

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:

Warning: Cannot modify header information - headers already sent by (output started at \\boswinfs02\home\users\web\b1623\ez.ultratek\practice\mysql_connect.php:28) in \\boswinfs02\home\users\web\b1623\ez.ultratek\practice\register.php on line 71

Link to comment
https://forums.phpfreaks.com/topic/134045-solved-redirectcont/#findComment-698806
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.