i do a survey in php
i would like to allow only one vote
but i don't know why, i can vote 2 times...
the survey display with this script: bd.php
Code: Select all
function sondage()
{
echo'<div id="sondage">';
if (!isset($_COOKIEї'sondage_cookies']))
{
$requete = "SELECT vot_libelle,vot_novote FROM vote ORDER BY vot_novote";
$result_vote = mysql_query ($requete);// or news_mysql_die();
$vote = mysql_fetch_object($result_vote);
echo'<div class="titre">';
print("<form name="Vote" method="post" action="vote.php"> $vote->vot_libelle</div>");
while ($vote = mysql_fetch_object($result_vote))
{
echo'<div class="element">';
print("<input type="radio" name="choix" value="$vote->vot_novote">$vote->vot_libelle");
echo'</div>';
}
print("<div class='element'><input type="submit" name="Submit2" value="Voter !"1: ></form></div>");
}
else
{
$requete = "SELECT vot_votants FROM vote WHERE vot_novote > 0";
$result_vote = mysql_query ($requete);// or news_mysql_die();
$total_vot_votants = 0;
while ($nb_vot_votants = mysql_fetch_object($result_vote))
$total_vot_votants = $total_vot_votants + intval($nb_vot_votants->vot_votants);
$requete = "SELECT * FROM vote ORDER BY vot_novote";
$result_vote = mysql_query ($requete);// or news_mysql_die();
$vote = mysql_fetch_object($result_vote);
echo'<div class="titre">'.$vote->vot_libelle.'</div>';
while ($vote = mysql_fetch_object($result_vote))
{
if ($total_vot_votants != 0)
$pcent_vote = round((intval($vote->vot_votants) / $total_vot_votants) * 100);
else
$pcent_vote = 0;
$pcent_vote_txt = strval($pcent_vote);
print("<div class="element">$vote->vot_libelle <b> $pcent_vote_txt %</b></div>");
}
}
print("</div>");
}bd.php post the result to vote.php
vote.php
Code: Select all
<?php
$jour = getdate();
$numjour = intval($jourї'wday']);
if ($numjour == 0)
$numjour = 7;
$numlundi = abs($numjour - 8) * 24 * 60 * 60;
$numheure = intval(date("H")) * 60 * 60;
$numminute = intval(date("i")) * 60;
$numseconde = intval(date("s"));
$expir = time() - $numseconde - $numminute - $numheure + $numlundi;
setcookie("sondage_cookies", "1", $expir);
include "bd.php";
connectionbd();
$choix = $_POSTї'choix'];
if ( isset($_POSTї'choix']) )
{
$requete = "SELECT vot_votants FROM vote WHERE vot_novote=".$choix;
$result_vote = mysql_query ($requete);
$vote = mysql_fetch_object($result_vote);
$nb_votants = intval($vote->vot_votants);
$nb_votants = $nb_votants + 1;
$votants = strval($nb_votants);
$requete = "UPDATE vote SET vot_votants=$votants WHERE vot_novote=".$choix;
mysql_query($requete);
}
$URL="http://laboiteaprog.com";
header ("Location: $URL");
?>http://laboiteaprog.com
any idea?
--
La boîte à prog http://laboiteaprog.com