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

Langage PHP Discussion :

Sondage sur site


Sujet :

Langage PHP

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2010
    Messages
    19
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 19
    Points : 20
    Points
    20
    Par défaut Sondage sur site
    Bonjour,

    Je ne savais pas trop où poster mon post tellement il y de forum ^^.

    Voila, je voudrais faire un sondage sur mon site, mais je n'y arrive pas j'ai trouvé sur un site ce script (j'ai laisser la question du site pour essayer, non je ne m'interesse pas au herbe aromatique ^^):

    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
    	Question : "L'arc cosinus, c'est une herbe aromatique ?"
    <form name="formulaire" method="post" action="<?$PHP_SELF?>">
    <input type="radio" name="choix" value="oui"> oui...
    <input type="radio" name="choix" value="non"> non...
    <input type="radio" name="choix" value="pas"> ne sait pas...
    <input type="submit" value="Validez votre réponse">
    </form>
     
    <?php
    switch($choix)
    {
    case "oui":
    $fichier = fopen("oui.txt","r+");
    $sond = fgets($fichier,255);
    $sond++;fclose($fichier);
    $fichier = fopen("oui.txt","w");
    fwrite($fichier,$sond);
    fclose($fichier);break;
     
    case "non":
    $fichier = fopen("non.txt","r+");
    $sond = fgets($fichier,255);
    $sond++;fclose($fichier);
    $fichier = fopen("non.txt","w");
    fwrite($fichier,$sond);
    fclose($fichier);break;
     
    case "pas":
    $fichier = fopen("pas.txt","r+");
    $sond = fgets($fichier,255);
    $sond++;fclose($fichier);
    $fichier = fopen("pas.txt","w");
    fwrite($fichier,$sond);
    fclose($fichier);break;
    }
    ?>
     
    <?php
    $fichier = fopen("oui.txt","r");
    $sonda = fgets($fichier,255);
    fclose($fichier);
     
    $fichier = fopen("non.txt","r");
    $sondb = fgets($fichier,255);
    fclose($fichier);
     
    $fichier = fopen("pas.txt","r");
    $sondc = fgets($fichier,255);
    fclose($fichier);
     
    $tot_sond=($sonda+$sondb+$sondc);
    echo "Nombre de \"oui\" : ",$sonda;
    echo "Nombre de \"non\" : ",$sondb;
    echo "Nombre de \"ne sait pas\" : ",$sondc;
    echo "Nombre total de votes : ",$tot_sond;
    ?>
    J'ai créé mes trois fichiers texte dans mon dossier, mais quand je test, il me renvois sur une page en disant qu'il trouve pas le fichier<?$PHP_SELF?>.

    merci

  2. #2
    Membre chevronné Avatar de nosferapti
    Profil pro
    Inscrit en
    Avril 2009
    Messages
    1 157
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2009
    Messages : 1 157
    Points : 1 895
    Points
    1 895
    Par défaut
    regarde le code source HTML du formulaire et tu verras le problème
    GNAP !

  3. #3
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    bien écrit ca donne ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <form name="formulaire" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Janvier 2010
    Messages
    19
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Janvier 2010
    Messages : 19
    Points : 20
    Points
    20
    Par défaut
    J'ai essayé mais ça ne marche pas, je ne vois pas d'où vient le problème.

  5. #5
    Membre chevronné Avatar de nosferapti
    Profil pro
    Inscrit en
    Avril 2009
    Messages
    1 157
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2009
    Messages : 1 157
    Points : 1 895
    Points
    1 895
    Par défaut
    Citation Envoyé par nosferapti Voir le message
    regarde le code source HTML du formulaire et tu verras le problème
    GNAP !

  6. #6
    Membre expert Avatar de Fench
    Homme Profil pro
    Chercheur en informatique
    Inscrit en
    Mai 2002
    Messages
    2 353
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Groenland

    Informations professionnelles :
    Activité : Chercheur en informatique
    Secteur : Administration - Collectivité locale

    Informations forums :
    Inscription : Mai 2002
    Messages : 2 353
    Points : 3 390
    Points
    3 390
    Par défaut
    Bonjour,

    Manque des choses dans ton code !

    Vu comme celà, il ne tournera pas

    $choix, il est initialisé comment?
    $choix = $_POST['choix'];

    Edit: Pour action, tu peux aussi essayer action="leNomDuPhpDuFormulaire.php"
    Meuuh en AI à l'INRA
    Domaines: {java, php, js, jquery}{hibernate, doctrine}{MyLib, symfony, Zend}
    fait gagner du temps à ceux qui aident , donc un message avec la balise résolu laisse plus de temps pour résoudre d'autres problèmes (balise à cliquer en bas de l'écran)

  7. #7
    Membre expérimenté Avatar de riete
    Homme Profil pro
    DevWeb - Oléiculteur
    Inscrit en
    Avril 2006
    Messages
    1 193
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France

    Informations professionnelles :
    Activité : DevWeb - Oléiculteur
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 193
    Points : 1 414
    Points
    1 414
    Par défaut
    J'imagine que tu débute? Voici ton code à qui j'ai fait subir un petit lifting , mais je te laisse encore du boulot.
    Si tu tiens à utiliser des fichiers texte pour faire ton sondage, il faut d'abord créer tes fichiers oui.txt, non.txt et pas.txt et les initialiser. Pour cela il faut d'abord tester leur existence.
    Je te laisse réfléchir à la suite et revenir ici si tu galère trop.
    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
    <html lang="fr">
    <head>
    	<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
    	<title>Untitled</title>
    </head>
    <body>
     
    		Question : "L'arc cosinus, c'est une herbe aromatique ?"
    	<form name="formulaire" method="post" action="<?php echo $PHP_SELF;?>">
    	<input type="radio" name="choix" value="oui"> oui...
    	<input type="radio" name="choix" value="non"> non...
    	<input type="radio" name="choix" value="pas"> ne sait pas...
    	<input type="submit" value="Validez votre réponse">
    	</form>
     
    	<?php
     
    	switch($_POST['choix']){
     
    		case "oui":
    		$fichier = fopen("oui.txt","r+");
    		$sond = fgets($fichier,255);
    		$sond++;fclose($fichier);
    		$fichier = fopen("oui.txt","w");
    		fwrite($fichier,$sond);
    		fclose($fichier);break;
     
    		case "non":
    		$fichier = fopen("non.txt","r+");
    		$sond = fgets($fichier,255);
    		$sond++;fclose($fichier);
    		$fichier = fopen("non.txt","w");
    		fwrite($fichier,$sond);
    		fclose($fichier);break;
     
    		case "pas":
    		$fichier = fopen("pas.txt","r+");
    		$sond = fgets($fichier,255);
    		$sond++;fclose($fichier);
    		$fichier = fopen("pas.txt","w");
    		fwrite($fichier,$sond);
    		fclose($fichier);break;
    	}
    	?>
     
    	<?php
    	$fichier = fopen("oui.txt","r");
    	$sonda = fgets($fichier,255);
    	fclose($fichier);
     
    	$fichier = fopen("non.txt","r");
    	$sondb = fgets($fichier,255);
    	fclose($fichier);
     
    	$fichier = fopen("pas.txt","r");
    	$sondc = fgets($fichier,255);
    	fclose($fichier);
     
    	$tot_sond=($sonda+$sondb+$sondc);
    	echo "Nombre de \"oui\" : ",$sonda;
    	echo "Nombre de \"non\" : ",$sondb;
    	echo "Nombre de \"ne sait pas\" : ",$sondc;
    	echo "Nombre total de votes : ",$tot_sond;
    	?>
    </body>
    </html>
    ----
    L'avenir appartient à ceux dont les salariés se lèvent tôt.

  8. #8
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    J'insiste par contre mais il faut utiliser $_SERVER['PHP_SELF'] depuis PHP4.1
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  9. #9
    Membre expérimenté Avatar de riete
    Homme Profil pro
    DevWeb - Oléiculteur
    Inscrit en
    Avril 2006
    Messages
    1 193
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 63
    Localisation : France

    Informations professionnelles :
    Activité : DevWeb - Oléiculteur
    Secteur : Bâtiment

    Informations forums :
    Inscription : Avril 2006
    Messages : 1 193
    Points : 1 414
    Points
    1 414
    Par défaut
    Effectivement, je n'avais pas remarqué ce détail.
    ----
    L'avenir appartient à ceux dont les salariés se lèvent tôt.

Discussions similaires

  1. sondage sur la possibilité de faire tester son site
    Par SpaceFrog dans le forum Mon site
    Réponses: 0
    Dernier message: 04/03/2009, 12h06
  2. Mettre un sondage sur un site Web
    Par perchman dans le forum Débuter
    Réponses: 6
    Dernier message: 06/06/2008, 21h32

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