Specifications
FIGURE 19.8
Vote results are created by drawing a series of lines, rectangles, and text items onto a canvas.
The new parts of this script relate to drawing lines and rectangles. We will focus our attention
on these sections. Part 1 (of this four-part script) is shown in Listing 19.5.1.
LISTING 19.5.1 showpoll.php—Part 1 Updates the Vote Database and Retrieves the New
Results
<?
/*******************************************
Database query to get poll info
*******************************************/
// log in to database
if (!$db_conn = @mysql_connect(“localhost”, “poll”, “poll”))
{
echo “Could not connect to db<br>”;
exit;
};
@mysql_select_db(“poll”);
if (!empty($vote)) // if they filled the form out, add their vote
{
$vote = addslashes($vote);
$query = “update poll_results
set num_votes = num_votes + 1
where candidate = ‘$vote’”;
if(!($result = @mysql_query($query, $db_conn)))
{
echo “Could not connect to db<br>”;
exit;
}
};
Advanced PHP Techniques
P
ART IV
422
24 7842 CH19 3/6/01 3:42 PM Page 422










