';
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
';
exit;
}
};
// get current results of poll, regardless of whether they voted
$query = 'select * from poll_results';
if(!($result = @mysql_query($query, $db_conn)))
{
echo 'Could not connect to db
';
exit;
}
$num_candidates = mysql_num_rows($result);
// calculate total number of votes so far
$total_votes=0;
while ($row = mysql_fetch_object ($result))
{
$total_votes += $row->num_votes;
}
mysql_data_seek($result, 0); // reset result pointer