I need help from one of the gurus again
I'm getting this message after sending data to mysql:
Successfully added
Warning: Cannot modify header information - headers already sent by (output started at /home/domainhere/public_html/sub/includes/gc_insert.php:1) in /home/domainhere/public_html/sub/includes/gc_insert.php on line 24
This is my code:
<?php
$con = mysql_connect("localhost","user","pass") or die("Could not connect:".mysql_error());
mysql_select_db("db", $con);
$sql = "INSERT INTO comments (status, name, city, state, zipcode, country, comment)
VALUES (
'". mysql_real_escape_string(htmlspecialchars($_POST['status']))."',
'". mysql_real_escape_string(htmlspecialchars($_POST['name']))."',
'". mysql_real_escape_string(htmlspecialchars($_POST['city']))."',
'". mysql_real_escape_string(htmlspecialchars($_POST['state']))."',
'". mysql_real_escape_string(htmlspecialchars($_POST['zipcode']))."',
'". mysql_real_escape_string(htmlspecialchars($_POST['country']))."',
'". mysql_real_escape_string(htmlspecialchars($_POST['comment']))."')";
if (!mysql_query($sql,$con)){
echo "there was an error";
}
else{
echo "Successfully added";
}
header('Location: index.php');
mysql_close($con);
?>
I have read about this error and I've made sure there are no white spaces anywhere, I've put the header line before displaying anything to the browser (echo) and the error still appears.
If I run var_dump(headers_list()); I get the following
array(2) { [0]=> string(24) "X-Powered-By: PHP/5.2.15" [1]=> string(23) "Content-type: text/html" }
But I don't see anything useful there that could help me fix the issue.
I know of a workaround which is using something like:
<meta http-equiv="refresh" content="1;URL=/index.php">
But I'd hate to use that, I just don't like it and I have other pages where I've used a header with no problem, I just don't know why in this case this is happening.
Any suggestions will be much appreciated, thanks everyone.