Bienvenu(e)! Identification Créer un nouveau profil

Recherche avancée

Code PHP - Sondage

Envoyé par Viinc 
Code PHP - Sondage
mercredi 27 août 2008 00:27:58
Salut,
J'ai suivi le tutoriel d'aide pour la création d'un sondage (qui semble très pratique, en effet) et modifié légèrement le code pour donner ceci :

<html>
<head>
<title>
Êtes-vous d'accord ?
</title>
</head>
<body>
<form name="formulaire" method="post" action="<?=$_SERVER['$PHP_SELF']?>">
<input type="radio" name="choix" value="oui"> Pour.
<input type="radio" name="choix" value="non"> Neutre.
<input type="radio" name="choix" value="pas"> Contre.
<input type="submit" value="Envoyer">
</form>
<?
switch($choix)
{
case "oui":
$fichier = fopen("oui.txt","r+"winking smiley;
$sond = fgets($fichier,255);
$sond++;fclose($fichier);
$fichier = fopen("oui.txt","w"winking smiley;
fwrite($fichier,$sond);
fclose($fichier);break;

case "non":
$fichier = fopen("non.txt","r+"winking smiley;
$sond = fgets($fichier,255);
$sond++;fclose($fichier);
$fichier = fopen("non.txt","w"winking smiley;
fwrite($fichier,$sond);
fclose($fichier);break;

case "pas":
$fichier = fopen("pas.txt","r+"winking smiley;
$sond = fgets($fichier,255);
$sond++;fclose($fichier);
$fichier = fopen("pas.txt","w"winking smiley;
fwrite($fichier,$sond);
fclose($fichier);break;
}
?>
<?
$fichier = fopen("oui.txt","r"winking smiley;
$sonda = fgets($fichier,255);
fclose($fichier);

$fichier = fopen("non.txt","r"winking smiley;
$sondb = fgets($fichier,255);
fclose($fichier);

$fichier = fopen("pas.txt","r"winking smiley;
$sondc = fgets($fichier,255);
fclose($fichier);

$tot_sond=($sonda+$sondb+$sondc);
echo "Nombre de \"pour\" : ",$sonda;
echo "Nombre de \"contre\" : ",$sondb;
echo "Nombre de \"neutre\" : ",$sondc;
echo "Nombre total de votes : ",$tot_sond;
?>
</body>
</html>


Y a-t-il un problème ? Lorsque j'envoie un vote, pourtant, ça ne fonctionne pas : ça reste à zéro. J'ai bien créer un page .php que j'ai nommée test (test.php) et les trois pages .txt réglementaires.

Besoin d'aide au plus vite,
je vous remercie d'avance. #clin#
Re: Code PHP - Sondage
dimanche 8 mars 2009 21:16:52
Bonjour,
As-tu libéré les fichiers.txt en écriture 0777 ?
JPaul
Seuls les utilisateurs enregistrés peuvent poster des messages dans ce forum.

Cliquez ici pour vous connecter