Jump to content

Archived

This topic is now archived and is closed to further replies.

gabenut

Image manipulation error

Recommended Posts

Hello,

I have been doing some work on making a survey with PHP and MySQL. I am having a problem displaying the image for the graph. I have been using the imagecreate() function in PHP.

The error displayed is: [b]The image "survey.php" cannot be displayed, because it contains errors.[/b]

Here's the coding:

[code]<?php
session_start();

Header("Content-Type: image/gif");


$query = "SELECT count(question_id) FROM final WHERE QuestionID=1";
$result = mysqli_query ($dbc, $query);
$row = mysqli_fetch_row($result);
$nTotalVotes=$row[0];

$query = "SELECT final.answer_id, answers.answer as tx, count (final.answer_id) as ct FROM final, answers WHERE final.answer_id = answer.answer_id AND final.question_id =1 GROUP BY final.answer_id";

$result = mysqli_query ($dbc, $query);
$xDim = 400;
$yDim = 15+(mysqli_num_rows($result)*15);
$im = ImageCreate($xDim, $yDim);
$backg = ImageColorAllocate($im, 255,255,200);
$blue = ImageColorAllocate($im, 0, 0, 255);
$nY = 0;
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
    $percVote = round(($row['ct']/$nTotalVotes)*100,2);
    $percWidth = ($percVote * $xDim / 100) - 10;
    ImageFilledRectangle($im, 0, $nY+1, $percWidth, $nY+10, $blue);
    ImageString($im,2,$percWidth + 5, $nY+1, $row['tx'] . " " . $percVote . "%", $blue);
    $nY=$nY+15;
}
ImageGIF($im);


?>[/code]

Any help would be greatly appeciated, thank you!

Share this post


Link to post
Share on other sites
Comment out the header line and run script

[code]// Header("Content-Type: image/gif");[/code]

Errors should then be reported.

And you need

[code]imagedestroy($im);[/code]

at end

Share this post


Link to post
Share on other sites
Thanks very much for your help. The errors I got were these:


Warning: mysqli_fetch_row() expects exactly 1 parameter, 2 given in survey.php on line 10

Warning: mysqli_num_rows() expects exactly 1 parameter, 2 given in survey.php on line 17

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in survey.php on line 22
GIF87a?

I'm not sure what these mean, so again, any help would be much appreciated. Thank you!

Share this post


Link to post
Share on other sites
Check queries working correctly and use something like

[code]$result = mysqli_query ($dbc, $query) or die(mysqli_error());[/code]

(I hope that's right, my v4 manual hasn't got msqli)

Share this post


Link to post
Share on other sites
Thank you very much! The errors have disappeared but now this is displayed:

GIF87a?

I took the comments away from the header, just to check, and the original error comes up.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.