Проблема е че тази анкета позволява неограничен брой гласувания
искам да я огранича чрез кукита
искам да я огранича чрез кукита
Код:
<?php
/*******************************************
Database query to get poll info
*******************************************/
include ('poll_conf.php');
// get vote from form
$vote=$HTTP_POST_VARS['vote'];
// log in to database
if (!$db_conn = @mysql_connect('localhost', 'egdob_polladmin', 'p57bmcz6'))
{
echo 'Could not connect to db<br />';
exit;
};
@mysql_select_db('egdob_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;
}
};
// get current results of poll, regardless of whether they voted
$query = 'select * from poll_results';
// connect
$result = mysql_query($query) or die(mysql_error());
$num_results = 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
echo '<p class="poll"><br>Общо гласували: '.$total_votes.'';
echo '<br />'.'<br />';
$answer = array( $vote1 , $vote2 , $vote3 );
for ($i=0; $i < $num_results; $i++)
{
$row = mysql_fetch_array($result);
echo htmlspecialchars(stripslashes($row['candidate'])).'. '.$answer[$i];
echo ' - '.($row['num_votes']);
echo '<br />';
//and so on..
}
?>