IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

EDI, CMS, Outils, Scripts et API PHP Discussion :

Voter uniquement une seule fois sur un sondage


Sujet :

EDI, CMS, Outils, Scripts et API PHP

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    284
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 284
    Points : 62
    Points
    62
    Par défaut Voter uniquement une seule fois sur un sondage
    bonjour,

    je suis entrain de crée un sondage sur un site afin d'avoir les opinions des visiteurs....
    Sur ce sondage, je souhaite le visiteur puissent voté uniquement une seule fois par sondage crée.
    Mon probléme lorsque le sondage comprend plusieurs vote, à chaque actualisation ou retour sur la page le sondage comptabilise le dernier vote dans la base de donnée.

    voici le script posant probléme

    j'insere le vote dans la bdd
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
       $vote_ip = $_SERVER['REMOTE_ADDR'];
        $sondage_id = $numeroDuSondage['nbre_entrees'];
        $sql = "INSERT INTO t_vote (sondage_id, vote_ip) VALUES ($sondage_id, '$vote_ip')";
        mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
    je selectionne si ya deja une ip pour ce sondage alors j'affiche avec le bouton voter:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
     
     
     if(!mysql_num_rows(mysql_query('SELECT * FROM t_vote WHERE sondage_id='.$sondage_id.' AND vote_ip="'.$vote_ip.'"')) > 0){
    //sondage avec bouton avant validation
    echo '<img src="img/_sondage.gif"><br>';
     
    echo '<div class="archives">'.$infos['question'].'</div>'.''. "";
     
    echo  '<div class="date">'.$infos['proposition1'].'</div>'.''.  "<input type='radio' name='sondage' value='prop1' id='prop1' /> <label for='prop1'>" .'<img src="img/sondage/vert.gif" height="16" width="' . $pourcentage_r1 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r1).'%" />' . '<img src="img/sondage/vert_droite.gif"/>' . round($pourcentage_r1) . "%<br />";
     
    echo  '<div class="date">'.$infos['proposition2'].'</div>'.''.  "<input type='radio' name='sondage' value='prop2' id='prop1' /> <label for='prop1'>" .'<img src="img/sondage/rouge.gif" height="16" width="' . $pourcentage_r2 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r2).'%" />' . '<img src="img/sondage/rouge_droite.gif"/>' . round($pourcentage_r2) . "% <br />";
     
     
     if ($infos['proposition3'] != "")
    echo  '<div class="date">'.$infos['proposition3'].'</div>'.''.  "<input type='radio' name='sondage' value='prop3' id='prop1' /> <label for='prop1'>" .'<img src="img/sondage/jaune.gif" height="16" width="' . $pourcentage_r3 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r3).'%" />' . '<img src="img/sondage/jaune_droite.gif"/>' . round($pourcentage_r3) . "% <br />";
     
           if ($infos['proposition4'] != "")
    echo  '<div class="date">'.$infos['proposition4'].'</div>'.''.  "<input type='radio' name='sondage' value='prop4' id='prop1' /> <label for='prop1'>" .'<img src="img/sondage/orange.gif" height="16" width="' . $pourcentage_r4 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r4).'%" />' . '<img src="img/sondage/orange_droite.gif"/>' . round($pourcentage_r4) . "% <br />";
     
    	        if ($infos['proposition5'] != "")
    echo  '<div class="date">'.$infos['proposition5'].'</div>'.''.  "<input type='radio' name='sondage' value='prop5' id='prop1' /> <label for='prop1'>" .'<img src="img/sondage/bleu.gif" height="16" width="' . $pourcentage_r5 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r5).'%" />' . '<img src="img/sondage/bleu_droite.gif"/>' . round($pourcentage_r5) . "% <br />";
     
     
    echo '<input type="submit" name="voter" value="Voter !"/><br /><br /><br /><br />';
    echo '<div align="right" class="archive"><a href="index.php?rub=game-editor">les résultats des anciens sondages +</a></div>';
    echo '<br/><br/><br/><br/><br/>';
    }
    sinon sans le bouton voter: ici à chaque actualisation de la page , il comptabilise un vote:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
     
     else {
    echo '<img src="img/_sondage.gif"><br>';
    if ($infos['question'] != "")
    echo '<div class="archives">'.$infos['question']. "";
    echo '</div>';
    if ($infos['proposition1'] != "")
    echo  '<div class="date">'.$infos['proposition1'].'</div>'.''.'<img src="img/sondage/vert.gif" height="16" width="' . $pourcentage_r1 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r1).'%" />'  . round($pourcentage_r1) . "%";
     
    	if ($infos['proposition2'] != "")
    echo  '<div class="date">'.$infos['proposition2'].'</div>'.''.'<img src="img/sondage/rouge.gif" height="16" width="' . $pourcentage_r2 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r2).'%" />'  . round($pourcentage_r2) . "% ";
     
    if ($infos['proposition3'] != "")
    echo  '<div class="date">'.$infos['proposition3'].'</div>'.''.'<img src="img/sondage/jaune.gif" height="16" width="' . $pourcentage_r3 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r3).'%" />' . round($pourcentage_r3) . "% ";
     
     
    	if ($infos['proposition4'] != "")
    echo  '<div class="date">'.$infos['proposition4'].'</div>'.''.'<img src="img/sondage/orange.gif" height="16" width="' . $pourcentage_r4 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r4).'%" />' . round($pourcentage_r4) . "% ";
     
         if ($infos['proposition5'] != "")
    echo  '<div class="date">'.$infos['proposition5'].'</div>'.''.'<img src="img/sondage/bleu.gif" height="16" width="' . $pourcentage_r5 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r5).'%" />' . round($pourcentage_r5) . "% <br /><br /><br /><br />";
     
    echo '<div align="right" class="archive"><a href="index.php">les résultats des anciens sondages +</a><br><br><br>';
    echo '<br/><br/><br/><br/><br/>';
    echo '</div>';
    }
    je n'arrive à voir ou provient l'erreur et le pourquoi?
    si une âme pourrais m'expliquer et me montrer avec beaucoup commentaire que je puisse progresser.....
    merci beaucoup
    sam

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    284
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 284
    Points : 62
    Points
    62
    Par défaut probléme avec le multivote en php
    bonjour,

    J'ai un problème avec un sondage en php pour gérer le multivote par ip.
    Lorsque j'actualise ma page, à partir d'un deuxiéme vote, il comptabilise toujours un nouveau vote dans la base de donnée. je ne vois pas d'ou peut provenir le probléme et ça résolution.

    script:
    on insere dans la base le vote du visiteur du sondage puis on regarde si on connait le visiteur par son ip et on affiche soit le formulaire avec le bouton valider ou sans bouton
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
     
    f(isset($_POST['sondage'])){
        $vote_ip = $_SERVER['REMOTE_ADDR'];
        $sondage_id = $numeroDuSondage['nbre_entrees'];
        $sql = "INSERT INTO t_vote (sondage_id, vote_ip) VALUES ($sondage_id, $vote_ip)";
        mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
    }
    ?>
    <br />
     
    <form method="post" name="sondage" >
    <?php
    $sql = "SELECT resultats1,resultats2,resultats3,resultats4, resultats5 FROM ".$table." WHERE id="."'" . $numeroDuSondage['nbre_entrees'] . "' ";
    $requete = mysql_query( $sql) or die( "ERREUR MYSQL numéro: ".mysql_errno()."<br>Type de cette erreur: ".mysql_error()."<br>\n" );
    while( $result = mysql_fetch_array( $requete ) )
    {
    //sondage aprés validation sans bouton
    $vote_ip = $_SERVER['REMOTE_ADDR'];
    $sondage_id = $numeroDuSondage['nbre_entrees'];
    $query = "SELECT vote_ip FROM '.table1 '. WHERE id="."'" . $numeroDuSondage['nbre_entrees'] . "' ";
    $result = mysql_query($query);
    if ($num > 0) {
     
    echo '<img src="img/_sondage.gif"><br>';
     
    echo '<div class="archives">'.$infos['question'].'</div>'.''. "";
     
    echo  '<div class="date">'.$infos['proposition1'].'</div>'.'' .'<div class="date1"><img src="img/sondage/vert.gif" height="16" width="' . $pourcentage_r1 / 100 * $long_max_bloc . '" alt=" '.round($pourcentage_r1).'%" /> ' . round($pourcentage_r1)  . "% (".$result["resultats1"]."votes)<br /></div>";
     
    echo  '<div class="date">'.$infos['proposition2'].'</div>'.'' .'<div class="date1"><img src="img/sondage/rouge.gif" height="16" width="' . $pourcentage_r2 / 100 * $long_max_bloc . '" alt=" '.round($pourcentage_r2).'%" /> ' . round($pourcentage_r2)  . "% (".$result["resultats2"]."votes)<br /></div>";
     
     
     if ($infos['proposition3'] != "")
    echo  '<div class="date">'.$infos['proposition3'].'</div>'.'' .'<div class="date1"><img src="img/sondage/jaune.gif" height="16" width="' . $pourcentage_r3 / 100 * $long_max_bloc . '" alt=" '.round($pourcentage_r3).'%" /> ' . round($pourcentage_r3)  . "% (".$result["resultats3"]."votes)<br /></div>";
     
           if ($infos['proposition4'] != "")
    echo  '<div class="date">'.$infos['proposition4'].'</div>'.'' .'<div class="date1"><img src="img/sondage/orange.gif" height="16" width="' . $pourcentage_r4 / 100 * $long_max_bloc . '" alt=" '.round($pourcentage_r4).'%" /> ' . round($pourcentage_r4)  . "% (".$result["resultats4"]."votes)<br /></div>";
     
    	        if ($infos['proposition5'] != "")
    echo  '<div class="date">'.$infos['proposition5'].'</div>'.'' .'<div class="date1"><img src="img/sondage/bleu.gif" height="16" width="' . $pourcentage_r5 / 100 * $long_max_bloc . '" alt=" '.round($pourcentage_r5).'%" /> ' . round($pourcentage_r5)  . "% (".$result["resultats5"]."votes)<br /></div>";
     
     
    echo '<div align="right" class="archive"><a href="index.php?rub=game-editor">les résultats des anciens sondages +</a></div>';
    echo '<br/><br/><br/><br/><br/>';
    }
     else {
     
    //sondage avec bouton avant validation
    echo '<img src="img/_sondage.gif"><br>';
     
    echo '<div class="archives">'.$infos['question'].'</div>'.''. "";
     
    echo  '<div class="date">'.$infos['proposition1'].'</div>'.''.  "<input type='radio' name='sondage' value='prop1' id='prop1' /> <label for='prop1'>" .'<span class="date2"><img src="img/sondage/vert.gif" height="16" width="' . $pourcentage_r1 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r1).'%" />' . '<img src="img/sondage/vert_droite.gif"/> ' . round($pourcentage_r1) . "% (".$result["resultats1"]."votes)<br /></span>";
     
    echo  '<div class="date">'.$infos['proposition2'].'</div>'.''.  "<input type='radio' name='sondage' value='prop2' id='prop2' /> <label for='prop2'>" .'<span class="date2"><img src="img/sondage/rouge.gif" height="16" width="' . $pourcentage_r2 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r2).'%" /> ' . round($pourcentage_r2) . "% (".$result["resultats2"]."votes)<br /></span>";
     
     
     if ($infos['proposition3'] != "")
    echo  '<div class="date">'.$infos['proposition3'].'</div>'.''.  "<input type='radio' name='sondage' value='prop3' id='prop3' /> <label for='prop3'>" .'<span class="date2"><img src="img/sondage/jaune.gif" height="16" width="' . $pourcentage_r3 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r3).'%" /> ' . round($pourcentage_r3) . "% (".$result["resultats3"]."votes)<br /></span>";
     
           if ($infos['proposition4'] != "")
    echo  '<div class="date">'.$infos['proposition4'].'</div>'.''.  "<input type='radio' name='sondage' value='prop4' id='prop4' /> <label for='prop4'>" .'<span class="date2"><img src="img/sondage/orange.gif" height="16" width="' . $pourcentage_r4 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r4).'%" /> ' . round($pourcentage_r4) . "% (".$result["resultats4"]."votes)<br /></span>";
     
    	        if ($infos['proposition5'] != "")
    echo  '<div class="date">'.$infos['proposition5'].'</div>'.''.  "<input type='radio' name='sondage' value='prop5' id='prop5' /> <label for='prop5'>" .'<span class="date2"><img src="img/sondage/bleu.gif" height="16" width="' . $pourcentage_r5 / 100 * $long_max_bloc . '" alt="'.round($pourcentage_r5).'%" /> ' . round($pourcentage_r5) . "% (".$result["resultats5"]."votes)<br /></span>";
     
     
    echo '<input type="submit" name="voter" value="Voter !"/><br /><br />';
    echo '<div align="right" class="archive"><a href="index.php?rub=game-editor">les résultats des anciens sondages +</a></div>';
    echo '<br/><br/>';
    }
    }
    }
    ca marche pour un seul vote, quand on atteint 100% mais lorsque il ya 2 votes minimum, il comptabilise le dernier vote a chaque raffraichissement de la page, besoin de vous pour une explication certainement tt simple.

    merci à vous!
    sam

  3. #3
    mon_nom_est_personne
    Invité(e)
    Par défaut
    creer un index unique dans ta table avec l'ip et l'id du vote
    en gros tu dit que pour chaque vote, une ip peut soumettre sa voix qu'un fois.

    apres http://dev.mysql.com/doc/refman/5.0/...duplicate.html et fin de l'histoire

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2006
    Messages
    284
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2006
    Messages : 284
    Points : 62
    Points
    62
    Par défaut
    salut,
    merci pour info
    problème réglé

    merci encore !!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 2
    Dernier message: 05/10/2013, 23h09
  2. Réponses: 2
    Dernier message: 12/03/2010, 10h35
  3. Survol ne fonctionne qu'une seule fois sur IE
    Par elekaj34 dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 10/08/2009, 14h06
  4. executer fonction javascript une seule fois sur un onchange
    Par sebdu dans le forum Général JavaScript
    Réponses: 13
    Dernier message: 24/08/2007, 14h44
  5. [VB6]opération sur un tableau complet en une seule fois?
    Par marco62118 dans le forum VB 6 et antérieur
    Réponses: 5
    Dernier message: 24/05/2006, 12h50

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo