This is my code..!!!
i use ob_start() but still i m getting header error


Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\flower\upload1.php:1) in C:\xampp\htdocs\flower\upload1.php on line 30

can anyone tell me where m i wrong.??
why this is error is related to header only..!!!
is there any other way to jump from one page to another..??

<?php 
 ob_start();
 include_once('config.php');


//This is the directory where images will be saved
$target = "photos/";
$target = $target . basename($_FILES['photo']['name']);

//This gets all the other information from the form
$firstname=$_POST['fname'];
$lastname=$_POST['lname'];
$bdate=$_POST['bdatey'].'-'.$_POST['bdatem'].'-'.$_POST['bdated'];
$ddate=$_POST['ddatey'].'-'.$_POST['ddatem'].'-'.$_POST['ddated'];
$creator=$_POST['creator'];
$pic=($_FILES['pic']['name']);
$about=$_POST['description'];
   echo $bdate;
   echo $ddate; exit();
      

//Writes the information to the database
mysql_query("INSERT INTO members (member_name,member_pic,member_description,member_creator,date_of_birth,date_of_death,country)
VALUES('$name', '$pic', '$about','$creator','$bdate','$ddate','India')") or die(mysql_error());

if(move_uploaded_file($_FILES['pic']['tmp_name'], $target))
{
    header('location:upload.phpq=1');
}
else {
header('location:upload.php?q=2');
}
?>

there can be no output to the browser before redirects
remove the echo statements at 18 19
those statements are useless
the two possible outcomes of the upload are covered by the if statement at 26

With the ob_start statement, the echo statements shouldn't be a problem however, they are redundant.

Try putting an ob_end_clean() before the header statements to clear the buffer and turn off the buffering.

You could do the same thing with forms or buttons but it would require user intervention so this approach is better (once it works).

when the file ends and the buffer is flushed
the result is the error noted in the op
the echo statements are before the redirect,
remove the echo and the code works
ergo error is the echo statements

I just use the echo to check value in variable and than i use exit() also which means code after exit should not run..!!
Now even after removing 'echo' my code showing Header error..!!
So i made little change in code..!! earlier i was running the query directly.. and now i put in a variable and excute it..!!

$check=mysql_query("INSERT INTO members (member_name,member_pic,member_description,member_creator,date_of_birth,date_of_death,country)
VALUES('$name', '$pic', '$about','$creator','$bdate','$ddate','India')") or die(mysql_error());
   if($check)
   {
if(move_uploaded_file($_FILES['pic']['tmp_name'], $target))
{
    header('location:upload.phpq=1');
}
   }
else {
header('location:upload.php?q=2');
}

Now i m not getting the header error.. but now getting this error
what should i do now.?

Warning: move_uploaded_file(photos/) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\xampp\htdocs\flower\upload1.php on line 26

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\phpBF.tmp' to 'photos/' in C:\xampp\htdocs\flower\upload1.php on line 26

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.