Code to display poll results. This works except is does not show the results transfer the results into bargraph.php. It appears nothing happens. The file showpoll and bargraph.php are saved in the same folder.
any thoughts why this is not working
[code=php]
<?
$host = ‘localhost’;
$user = ‘root’;
$pass = ‘password’;
$db = ‘mydata’;
print “<html>n”;
print “<head>n”;
print “<title>Vote totals</title>n”;
print “</head>n”;
print “<body>n”;
$dbcon = mysql_connect($host, $user, $pass)
or die(‘Unable to connect to server ‘ . $host);
mysql_select_db($db) or die(‘Unable to find database ‘ . $db);
if(isset($_POST[‘vote’]) && ctype_digit($_POST[‘vote’])) {
$query = ‘UPDATE poll_answers SET votes=votes+1
WHERE choice=’ . $_POST[‘vote’];
$result = mysql_query($query);
}
$num_votes_query = ‘SELECT SUM(votes) AS sumvotes
FROM poll_answers’;
$num_votes_query .= ‘ WHERE poll_num=1’;
if ($result = mysql_query($num_votes_query)) {
$row = mysql_fetch_array($result);
$sum = $row[‘sumvotes’];
}
$totals_query = ‘SELECT activity, votes FROM poll_answers ‘;
if ($result = mysql_query($totals_query)) {
print “<table>n”;
print “<tr><th>Activity</th><th>Votes</th></tr>n”;
while($row = mysql_fetch_array($result)) {
print “<tr><td>” . $row[‘activity’] . “</td>n”;
print “<td align=”right”>” . $row[‘votes’] . “</td></tr>n”;
if($sum) {
$percent = round($row[‘votes’] * 100 / $sum);
print “<tr><td><img src=”bargraph.php?pct=$percent”></td>n”;
print “<td align=”right”>” . $percent . “%</td></tr>n”;
}
}
print “</table>n”;
}
print “</body>n”;
print “</html>n”;
?>
bargraph.php file code
[code=php]
<?php
$height = 10;
$width = 100;
$im = imagecreate($width, $height);
$bg = imagecolorallocate($im, 255, 255, 255); // white
$fg = imagecolorallocate($im, 255, 0, 0); // red
imagefilledrectangle($im, 0, 0, $_GET[‘pct’], $height, $fg);
imagerectangle($im, 0, 0, $width, $height, $bg);
header(“Content-type: image/png”);
imagepng($im);
imagedestroy($im);
?>