FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


header already sent? (and now introducing a mysql problem)





mahirh
hello , php lords , please help me resolve this problem,
im trying to make a dynamic signature which shows the name of the person as well as how many people had viewed it , but when i execute it , it cant modify the header , it claims that headers were already sent but there was no echo or stuff like that disabling the hit counter also did not solve anything
Code:

Warning: Cannot modify header information - headers already sent by (output started at E:\xampp\htdocs\stat.png\index.php:2) in E:\xampp\htdocs\stat.png\index.php on line 3
PNG  IHDRG* IDATxymGU.Qs ݜ}rD.(6?>'!@>zUAAjnHyC0zߵ(F6A   ivfQ59\k} u{Κ͚U_}5j(c~D[ /n+qw=@Nէ߳_^Vn/XOQÁX]a>VvwB. 4 i:   .·=ͧ{m<*<@;=zKn&.\PRz?ani)s@_^]X*)   RRtuW(og³..........

(rest can be viewed at http://frihost.pastebin.com/BpVDDNAf)
and my source code is
Code:
<?php
header('Content-Type: image/png');

 mysql_connect("localhost", "175697_mahirh", "******") or die(mysql_error());
 mysql_select_db("mahirh_zymichost_count") or die(mysql_error());

 mysql_query("UPDATE counter SET counter = counter + 1");


 $count = @mysql_fetch_row(mysql_query("SELECT counter FROM counter"));




function LoadPNG($imgname)
{

    $im = @imagecreatefrompng($imgname);


    if(!$im)
    {

        $im  = imagecreatetruecolor(150, 30);
        $bgc = imagecolorallocate($im, 255, 255, 255);
        $tc  = imagecolorallocate($im, 0, 0, 0);

        imagefilledrectangle($im, 0, 0, 150, 30, $bgc);


        imagestring($im, 1, 5, 5, 'Error loading ' . $imgname, $tc);
    }

    return $im;
}

//header('Content-Type: image/png');

$people = "$count[0]";
$img = LoadPNG('sig.png');
$textcolor = imagecolorallocate($img, 0, 0, 0);
imagestring($img, 3, 127, 62,"Mahirh!!",$textcolor);
imagestring($img, 3,265, 62,$count[0],$textcolor);
imagepng($img);


?>

i wonder if die(mysql_error()) is causing any problem , but even when i commented it and ran it , it showed the same problem
sonam
If your source code is right you have one empty line before <?php ... In that case you cannot send header because php send errror. Clear this line and any space before <?php if you need headers.

Sonam
mahirh
thanks sonam , so thats what created all these , i did not know that php was such sensitive to even bank lines
but , wait a second , i do think there is another problem , look at the code even after that line deleted, it doesn't show the number of hits , it s simply blank it only shows the mahirh!! thing and the background
http://mahirh.zymichost.com/stat.png/
sonam
I don't know to much about image creation. But maybe you cannot use twice imagestring function. Try to reverse to see what happens. BTW, you are define variable $people and don't use it.

Sonam
mahirh
i dont think an unused variable can be a culprit , I've even commented the line
Code:
magestring($img, 3, 127, 62,"Mahirh!!",$textcolor);

and the line
Code:
$people = "$count[0]";

and moreover php parses stuff before showing them , so all errors are pointed out
you might even have noticed theese
Code:
mysql_connect("localhost", "175697_mahirh", "***********") or die(mysql_error());
 mysql_select_db("mahirh_zymichost_count") or die(mysql_error());

so that it will report mysql errors
if the using twice is the problem , it should show up when i have commented it but still i dont understand what do you mean by saying
Quote:
Try to reverse to see what happens

and its hosted at http://mahirh.zymichost.com/stat.png/
sonam
Why I need to see reverse? Because now I can not see your name printed. In that case 60% is sure you cannot use imagestring twice. But here is 40% rest and maybe I am wrong. And, yes maybe is something wrong in sql command. In this moment I haven't time to try. How is looking your table. Is there only one column?

Sonam
mahirh
i think its most probably a mysql error because i was wondering why there was not even a table in the database which means there is some problem which is failing to show up even with
Code:
die(mysql_error());

added
and the screen shot of the sql client is (too bad my hosting provider doesn't use PhpMyAdmin )
sonam
Yeah, you need to crate or upload counter table.

Sonam
mahirh
looks like i forgot to import the sql file from my php my admin , but my host is down....
Related topics
phpbb problem....
Header("Location: PROBLEM");
Help for sending 2+ cookies in one page.
My Site (In it's infancy)
Websites hacked/defaced on Server 2
Wurm/Hacker
phpBB header problem.
Header phase problem
Problem in Uploading Avatar!
How to send a save session
MySQL adapter "mysql" is not available.
header_already_sent!
*Super Duper Urgent* "Headers Already Sent"
<?php ?> Tags
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.