Hello guys, I need your Help, why i can get this warning?

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\OJT\FINAL\profile.php:112) in C:\xampp\htdocs\OJT\FINAL\profile.php on line 122

this is my code


$result=mysql_query("select * from user where id='$member_id'")or die(mysql_error);


header("Content-Type: image/jpeg");
echo $image1;


4 Years
Discussion Span
Last Post by jovstudios

Usually it has to do with whitespace before <?php or after ?>.

Sometimes it has to do with session_start(); being called twice, normally in diferent files. If that's the case then you need to test if(!headers_sent()) and put your session_start(); in there.

There is a fix for it if it's none of the above try using ob_start(); at the very beggining of the 1st file. Link


Thanks Sir, Its Already Fix. I have a Question Sir, How do i Set Default image for user if the user has not uploaded thier own pics? using that code?

$defaultImage = 'images/default.png';
$image1 = ($row['img']) ? $row['img'] : $defaultImage;

this is my code sir, but still not working. Help me to correct this sir. thanks


include('dbcon.php');//para sa connection sang database

    $id = mysql_real_escape_string($_SESSION['id']);
    $result=mysql_query("select * from user where id='$id'")or die(mysql_error);

    $defaultImage = 'img/images.jpg';
    $image = ($row['img']) ? $row['img'] : $defaultImage;

        echo $image;


Edited by jovstudios


I think you're testing one variable, then using another. Try replacing this:

    $id = mysql_real_escape_string($_SESSION['id']);

With this:

    $id = mysql_real_escape_string($_GET['id']);

Keep in mind mysql_real_escape_string is deprecated.

Try posting the errors you're getting so we know what to look for in your code.

** EDIT **

Oh, I just notived, you're missing the while statement to iterate through the $row array. That is if you have more then one result, in which case you would need to change the mysql_fetch_array to mysql_fetch.

    //post $row info

Unless you're working with some legacy project you should also choose a diferent API to connect to MySQL since the one you're using has several deprecated functions. Try looking up mysqli or PDO instead. Here's the myslqi overview.

Edited by Fernando_4: Added more info


This doesn't make much sense. Why are you checking for a GET id when you're using a SESSION id?

Check for number of rows returned

Place session_start() before anything else.

Use mysqli or PDO - mysql is gonna die.

I'm assuming that the $row['img'] is in blob field and not just a filename


I dont know how to use mysqli and PDO. only Mysql i already know sir, Thanks Sir, I ill try my very best to soved this issued.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.