PDA

View Full Version : cannot modify header in redirect function?


swissbeets
07-04-2008, 03:33 PM
INSERT INTO products ( position, product_name, product_type, product_price, product_description ) VALUES ( '1', 'chris', 'tshirt', 12.99, 'this is me' )
Warning: Cannot modify header information - headers already sent by (output started at create_product.php:5) in includes/functions.php on line 63

function redirect_to( $location = NULL )
{
if ($location != NULL) {
header("Location: {$location}");
exit;
}
}


it works on my localhost but not when the site is hosted.... this is my first time ever hosting a site, any suggestions greatly appreciatted

lux
07-04-2008, 03:46 PM
you cant print/echo anything to the browser before a header redirect(location)

view the page source and see what character is being displayed and remove it from your code.

hope that's clear

swissbeets
07-04-2008, 04:12 PM
i understand what you are saying i think but since that function is calling the new page nothing is being echo/printed first right? this is my create_product the only thing i can think of is the echo $query?

<?php require_once("includes/session.php"); ?>
<?php require_once("includes/connection.php"); require_once("includes/functions.php");
confirm_logged_in();

$errors = array();
$position = mysql_prep($_POST['position']);
$product_name = mysql_prep($_POST['product_name']);
$product_type = mysql_prep($_POST['product_type']);
$product_description = mysql_prep($_POST['product_description']);
$product_price = mysql_prep($_POST['product_price']);


$query = "INSERT INTO products (
position, product_name, product_type, product_price, product_description
) VALUES (
'$position', '$product_name', '$product_type', $product_price, '$product_description'
)";


echo $query;
$result = mysql_query($query, $connection);
if ($result) {
// Success!
redirect_to("content.php");
} else {
// Display error message.
echo "<p>Product creation failed.</p>";
echo "<p>" . mysql_error() . "</p>";
}
mysql_close($connection); ?>

lux
07-04-2008, 04:16 PM
well done you found it - remove echo $query and you wont see the error

swissbeets
07-04-2008, 04:24 PM
i did it and i am still coming up with the same error, your saying nothing can be echoed at all on my create_product page? or just in the redirect function? this is what i am confused about i think