0
<?php
$link=mysql_connect("localhost", "root","parola") or die("Could not connect: " . mysql_error());
print ("Connected successfully");print "</br>";
mysql_select_db('energiesolara',$link) or die ('Can\'t use energiesolaradb: ' . mysql_error());
$x=mysql_query("SELECT umiditate FROM parametrii");
$y=mysql_query("SELECT temperatura FROM parametrii");
$info1 = mysql_fetch_array($x);
$info2 = mysql_fetch_array($y);
$xi=array($info1['umiditate']);
$yi=array($info2['temperatura']);
include('phpgraphlib.php');
$graph=new PHPGraphLib(500,280);
$graph->addData($xi,$yi);
$graph->setTitle('Grafic');
$graph->setTitleLocation('left');
$graph->setLegend(true);
$graph->setLegendTitle('Module-1', 'Module-2');
$graph->setGradient('green', 'olive');
$graph->createGraph();
?>

I have this error :(


Connected successfully

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\xampp\htdocs\charty.php:3) in C:\xampp\xampp\htdocs\phpgraphlib.php on line 163
‰PNG IHDRôŽôA¿PLTEÿÿÿÜÜÜÈÈÈdddYYYYYYYY YYYYYYYYYYYYYYYYYY!Y

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

4
Contributors
4
Replies
7
Views
7 Years
Discussion Span
Last Post by metalix
0

That's because the graph class you use to output the image is trying to set some image headers, but you already outputed some stuff (from your print commands) before it, which php don't allow.
So:
1. This should fix your error: remove all the prints before phpgraphlib.php; leave only the error dies (if the script dies, it won't get to the graph lib anyway)
2. Just an improvement: select both mysql values in a single select:

$result = mysql_query("SELECT umiditate, temperatura FROM parametrii");
$info = mysql_fetch_array($result);
$xi=array($info['umiditate']);
$yi=array($info['temperatura']);
0

remember there can be nothing sent to the browser before your php codes.
sometimes if your using mysql you need sessions which should always start at the top. i had this problem a while ago and this fixed my problem.

<?php 
if (!isset($_SESSION)) {
  session_start();
}
require_once(connections.php');

?>
0

as an added note you dont need the require because your password and connection details are in your page. i just use it for security

This topic has been dead for over six months. 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.