View Full Version : cannot modify header in redirect function?

07-04-2008, 02: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}");

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

07-04-2008, 02: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

07-04-2008, 03: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");

$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
'$position', '$product_name', '$product_type', $product_price, '$product_description'

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

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

07-04-2008, 03: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