Jump to content

[SOLVED] Get header before form is submitted and redirected....


ndjustin20

Recommended Posts

Here is the script I am working on:

 


<?php

#$page_title = 'New Register Page';

#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']);
}//closing bracket for fist name if statement

if(empty($_POST['last_name'])) {
$errors[] = 'You forgot to enter your last name.';
}else{
$ln = escape_data($_POST['last_name']);
}//closing bracket for last name if statement

if(empty($_POST['email'])) {
$errors[] = 'You forgot to enter your email address';
}else{
$e = escape_data($_POST['email']);
}//closing bracket for email if statement

if(!empty($_POST['password1']) && ($_POST['password1'] == $_POST['password2'])) {
$pw = escape_data($_POST['password1']);
}else{
$errors[] = 'The password you entered and the password confirmation do not match each other.';
}//closing bracket for password if statement

if(empty($errors)) {
$query = "SELECT userid FROM users WHERE email='$e'";
$result = @mysql_query($query);
$rows = mysql_num_rows($result);
}//closing bracket for if the errors array is empty


if ($rows > 0) {
echo "I am sorry we can not register you at this time because $e is already taken";
}else{
$npw = SHA1('$pw');
$query = "INSERT INTO users (first_name, last_name, email, password, registration_date)
VALUES ('$fn', '$ln', '$e', '$npw', 'NOW()')";
$result = @mysql_query($query);
}//end the if statment that checks to see if the email address provided has already been taken


if($result) {

$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);   
   if ((substr($url, -1) == '/') OR
     (substr($url, -1) == '\\') ) {$url = substr ($url, 0, -1);   
}//end the if result is true conditional

   $url .= '/thanks.php';
   header("Location: $url");
   exit();
}else{
$result = FALSE;
$errors[] = 'You could not be registered do to a system error';
$errors[] = mysql_error() . '<br /><br />Query: ' . $query;
}

$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>';
   }
}//end main if submitted statement
?>
<h1>Register Here</h1>
<form action="register_brandnew.php" method="post">
<p>First Name<input type="text" name="first_name" value="<?php if(isset($_POST['first_name'])) echo $_POST['first_name'];?>" size="15" maxlength="20" /></p>
<p>Last Name<input type="text" name="last_name" value="<?php if(isset($_POST['last_name'])) echo $_POST['last_name'];?>" size="15" maxlength="20" /></p>
<P>Email Address<input type="text" name="email" value="<?php if(isset($_POST['email'])) echo $_POST['email'];?>" size="15" maxlength="20" /></P>
<p>Enter Password<input type="password" name="password1" size="15" maxlength="40" /></p>
<p>Confirm Password<input type="password" name="password2" size="15" maxlength="40" /></p>
<p><input type="submit" name="submit" value="Register" /></p>
<p><input type="hidden" name="submitted" value="TRUE" /></p>
</form>
<?php
include('./includes/Footer.html');
?>

 

What I am trying to figure out is how would you get the header information to load if the form hasn't been submitted?  Everything works in the form and can be found here www.freedomthinking.com/register_brandnew.php

 

 

Thank you for your help.

 

Justin

Try setting a javascript top.open function to your destination site when registered. If everything is satisfied:

<?php
if($login = "success"){

   $onLoad= "onLoad=\"top.open('success.php','_SELF')\"";

}else{

    $onLoad = "";

}
?>

 

Now in your body tag do this:

<body <?php echo $onLoad?>>

I have used this in many cases and it works but you have to account for people with js disabled. So add a direct click link. I would set a variable equal to something like: If your not redirected shortly, click HERE and here would be your success.php href.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.