Jump to content

RE: REDIRECT PAGE - 05.22.11


mrjap1

Recommended Posts

Hello,

 

Please... could someone look at my existing code below at tell me how I can establish a REDIRECT PAGE {header("Location: thankyou.php");} to fit in my code and WITHOUT  generating a MySQL error once the php page is processed on the server?

 

I wish to place the HTML CODE at bottom of my page labeled " // THE RESULTS OF THE FORM RENDERED AS PURE HTML  " to be on a separate " thanks.php " page.

 

thx

mrjap1

 



<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$registration_date = $_POST['registration_date'];


// 1. Create a database connection
$con = mysql_connect("localhost","mrino_mydata","runns100");

if (!$con) {
  die('Database connection failed could not connect: ' . mysql_error());
  }
  
// 2. Select a database to use
$db_select = mysql_select_db("mrino_FULLENTRYDATA",$con);
if (!$db_select) {
  die('Database selection failed could not connect: ' . mysql_error());
}

mysql_select_db("mrino_FULLENTRYDATA", $con);

// Data Submitted With My Form

$sql="INSERT IGNORE INTO  `mrino_FULLENTRYDATA`.`backpage1` (`id` , `first_name` , `last_name` , `email` , `registration_date`) VALUES (NULL ,  '$_POST[first_name]' ,  '$_POST[last_name]' ,  '$_POST[email]', NOW( ))";


if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());

}

// 3. Close Connection
mysql_close($con);
?>



<?php
// ALL THE SUBJECT and EMAIL VARIABLES

$emailSubject = 'MY TEST EMAIL SCRIPTING!!! ';
$webMaster = 'myemailaddress@gmail.com';

// GATHERING the FORM DATA VARIABLES

    $first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$registration_date = $_POST['registration_date'];
$date = date ("l, F jS, Y");
    $time = date ("h:i A");


$body = <<<EOD
<br /><hr><br />
<strong>First Name:</strong> $first_name <br />
<strong>Last Name: </strong>$last_name <br />
<strong>Email:</strong> $email <br />
<strong>Registration Date:</strong> $date at $time <br />
EOD;


// THIS SHOW ALL E-MAILED DATA, ONCE IN THE E-MAILBOX AS READABLE HTML

// Remove Header Injections
$match = "/(bcc:|cc:|content\-type:)/i";
if (preg_match($match, $from) ||
	preg_match($match, $subject) ||
	preg_match($match, $body)) {
  die("Header injection detected.");
}

// Simple filtering on all of our input variables
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);
$from = preg_replace("([\r\n])", "", $_POST['email']);
    $emailSubject = preg_replace("([\r\n])", "", $_POST['$emailSubject']);



// THE RESULTS OF THE FORM RENDERED AS PURE HTML 

$theResults = <<<EOD
<!DOCTYPE HTML>
<html lang="en">
<head>
<style type="text/css">
body {
font-family:Arial, Helvetica, sans-serif;
font-size:11px;
font-weight:bold;
}

#thankyou_block {
width: 400px;
height: 250px;
text-align:center;
border: 1px solid #666;
padding: 5px;
background-color: #0CF;
border-radius:8px;
-webkit-border-radius:8px;
-moz-border-radius:8px;
-opera-border-radius:8px;
-khtml-border-radius:8px;
box-shadow:0px 0px 10px #000;
-webkit-box-shadow: 0px 0px 10px #000;
-moz-box-shadow: 0px 0px 10px #000;
-o-box-shadow: 0px 0px 10px #000;
margin: 25px auto;
}

p {
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
line-height: 18px;
letter-spacing:1px;
color: #333;
}

</style>
<meta charset="UTF-8">
<title>THANK YOU!!!</title>
</head>

<body>

<div id="thankyou_block">
<br><br><br>
<h1>CONGRATULATIONS!!</h1>
<h2>YOUR FORM HAS BEEN PROCESSED!!!</h2>
<p>You are now registered in our Database...<br>
we will get back to you very shortly.<br>
Please have a very wondeful day.</p>

</div>
</body>
</html>
EOD;
echo "$theResults";


?>



Link to comment
Share on other sites

Hello,

 

Thank you, Thank you, very, very kindly for your suggestion... however, I know that the header will not work if something is currently processed before hand... I tried your exact recommendation earlier before I wrote this post.

 

What I have is a Form being processed before hand from another php page. Then the form processing take place on this page ( with the code presented in this post ).... next I would like the visitor to go to a separate " thank you.php " page when everything is complete.

 

The question is,  is it indeed possible or a way that I can get a redirect without generating the error stated below.

 

Maybe I am going about this the wrong way... I am open for any solutions. I know this can be done I just do not know how.

 

The "/~/ " are my url paths.

 

Warning: Cannot modify header information - headers already sent by (output started at /~/~/~/shortform/form_proceessed2011-NEW.php:67) in /~/~/~/shortform/form_proceessed2011-NEW.php on line 180

 

 

thx

mrjap1

Link to comment
Share on other sites

On line 67 in form_proceessed2011-NEW.php there is some form of output therefore header() will not work. The solution would be to modify your script so there is no output before the use of the header() function. Or for a simple fix revert to using output buffering.

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.