Bonjour,
Je viens de parcourir le forum, sans trouver la solution à mon problème... mais c'est probablement parce que je suis débutant en PHP :-(
J'aimerais faire un sondage en PHP. Après qq recherches sur internet, j'ai trouvé un code qui pouvait convenir et j'ai essayé de l'adapter (voir ci-dessous). Malheureusement, ça ne fonctionne pas et je ne comprends pas pourquoi. Tous mes fichiers txt sont créés et en 777.
Quelqu'un pourrait-il aiguiller mes recherches?
Un grand merci d'avance.
<form name="formulaire" method="post" action="<? $PHP_SELF;?>">
<table width="148" border="0">
<tr>
<td width="138"><p>
<input type="radio" name="radiobutton" value="excellent">
excellent </p>
<p>
<input type="radio" name="radiobutton" value="très bien">
très bien </p>
<p>
<input type="radio" name="radiobutton" value="bien">
bien </p>
<p>
<input type="radio" name="radiobutton" value="mauvais">
mauvais </p>
<p>
<input type="radio" name="radiobutton" value="très mauvais">
très mauvais</p>
<p><input type="submit" value="Validez votre choix">
</p></td>
</tr>
</table>
<p> </p>
</form>
<?
switch($choix)
{
case "excellent":
$fichier = fopen("excellent.txt","r+");
$sonda = fgets($fichier,255);
$sonda++;fclose($fichier);
$fichier = fopen("excellent.txt","w");
fwrite($fichier,$sonda);
fclose($fichier);break;
case "TB":
$fichier = fopen("TB.txt","r+");
$sond = fgets($fichier,255);
$sond++;fclose($fichier);
$fichier = fopen("TB.txt","w");
fwrite($fichier,$sond);
fclose($fichier);break;
case "bien":
$fichier = fopen("bien.txt","r+");
$sond = fgets($fichier,255);
$sond++;fclose($fichier);
$fichier = fopen("bien.txt","w");
fwrite($fichier,$sond);
fclose($fichier);break;
case "mauvais":
$fichier = fopen("mauvais.txt","r+");
$sond = fgets($fichier,255);
$sond++;fclose($fichier);
$fichier = fopen("mauvais.txt","w");
fwrite($fichier,$sond);
fclose($fichier);break;
case "TM":
$fichier = fopen("TM.txt","r+");
$sond = fgets($fichier,255);
$sond++;fclose($fichier);
$fichier = fopen("TM.txt","w");
fwrite($fichier,$sond);
fclose($fichier);break;
}
?>
<?
$fichier = fopen("excellent.txt","r");
$sonda = fgets($fichier,255);
fclose($fichier);
$fichier = fopen("TB.txt","r");
$sondb = fgets($fichier,255);
fclose($fichier);
$fichier = fopen("bien.txt","r");
$sondc = fgets($fichier,255);
fclose($fichier);
$fichier = fopen("mauvais.txt","r");
$sondd = fgets($fichier,255);
fclose($fichier);
$fichier = fopen("TM.txt","r");
$sonde = fgets($fichier,255);
fclose($fichier);
$tot_sond=($sonda+$sondb+$sondc+$sondd+$sonde);
echo "<p>Nombre de \"excellent\" : ".$sonda."</p>";
echo "Nombre de \"TB\" : ".$sondb."</p>";
echo "Nombre de \"bien\" : ".$sondc."</p>";
echo "Nombre de \"mauvais\" : ".$sondd."</p>";
echo "Nombre de \"très mauvais\" : ".$sonde."</p>";
echo "Nombre total de votes : ".$tot_sond."</p>";
?>