<?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

Recommended Answers

All 4 Replies

Make sure there is no space before <?php and after ?> too

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']);

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');

?>

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

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.