Jump to content

[SOLVED] how to redirect page after include


phplearner2008

Recommended Posts

Hi,

I have a file Interest_Sent.php where there is a checkbox and delete button, When the checkbox is checked and delete is pressed, it goes to process.php.

 

I am posting the code below:

<?php
include_once('C:\Program Files\Apache Group\Apache2\htdocs\matrimonial\config.php');
$MY_ID = $_POST['MY_ID'];
if(isset($_SERVER['HTTP_REFERER'])) $ref = $_SERVER['HTTP_REFERER'];
if($ref == 'http://localhost/matrimonial/templates/Interests_Sent.php')
{
$checkbox = array();
$checkbox = $_POST['box'];
$count = count($checkbox);
for($i=0;$i<$count;$i++)
{
   $value = $checkbox[$i];
$sql = "UPDATE interests_sent SET DELETED = 'Yes', DELETED_DATE = CURDATE() WHERE MY_ID = '$MY_ID' AND INTEREST_SENT = '$value' AND DELETED = 'No'";
$result = mysql_query($sql);
if($result)
{
  ob_start();  //start buffer
include('C:\Program Files\Apache Group\Apache2\htdocs\matrimonial\Interests_Sent.php');
//we pass the output of include file to a variable
$buffer = ob_get_contents();
ob_end_clean();
header("Location:http://localhost/matrimonial/templates/Interests_Sent.php");
}  else echo "Could not delete"; 
} 

} ?>

The above code works fine except for last but one line(header line). How do I redirect my page to Interests_Sent.php after these operations at process.php is completed?

 

In other words how can I redirect a page after using include without getting "Headers already sent" error?

 

Thanks.

 

Link to comment
Share on other sites

You can't output data to the browser before headers are sent, so you need to keep things on the server before the page is redirected.

 

If you need to include things from that page use a javascript redirect being called on load.

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.