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

<?php
$member_id=mysql_real_escape_string($_SESSION['id']);

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

$username=$row['UserName'];
$FullName=$row['FullName'];
$image1=$row['img'];

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

Thanks

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?

Member Avatar
diafol
$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

<?php

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


if(isset($_GET['id'])){
    $id = mysql_real_escape_string($_SESSION['id']);
    $result=mysql_query("select * from user where id='$id'")or die(mysql_error);
    $row=mysql_fetch_array($result);

    $defaultImage = 'img/images.jpg';
    $image = ($row['img']) ? $row['img'] : $defaultImage;
    header('Content-Type:image/jpeg');

        echo $image;

}
?>

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

if(isset($_GET['id'])){
    $id = mysql_real_escape_string($_SESSION['id']);

With this:

if(isset($_GET['id'])){
    $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.

while($row){
    //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.

Member Avatar
diafol

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.