Rand en php et boucle do while

Fermé
rourou - 8 déc. 2009 à 14:14
gigaga Messages postés 2346 Date d'inscription vendredi 20 juin 2008 Statut Membre Dernière intervention 22 août 2014 - 10 déc. 2009 à 20:33
Bonjour,
je fait un formelaire (2 cases),il ya une case qui contient un numero aletoire ensuite je remplir le deuxieme case par un numero quelq et je teste est-ce que le numero egale au numero aletoire ou non aussi il est grand ou petit je le droit de repeteer 10 fois ,mon probleme que le fonction rand ne marche pas et toujours affiche le numero est plus grand et le calcul de nombre de essais qui est restée ne marche pas .merciiiiiiiiiiiiiiiiiiiii
voila mon programme:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Document sans titre</title>
</head>

<body>
<style type="text/css">
body {font-family: "Verdana;";
background-color:#e2e3eb ;
color:#5E4A5E;
font-weight:bold;
background-repeat: no-repeat;}
.Style1{background-color:#5E4A5E;
color:#FFFFFF;
text-decoration:underline;}
.Style2{color:#FF0000;}
Style3 {color:#9900FF;}

</style>

</head>

<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<table width="800" border="0" cellspacing="0" cellpadding="0" align="center">
<tr bgcolor="#000066">
<td colspan="2" align="center" class="Style1"><h2>JEU DE DEVINETTE</h2></td>
<tr>
<td width="164"> </td>
<td width="236"> </td>
<tr>
<td width="600" height="33">derrière cette case se cache le nombre a deviner</td>
<td width="236"><input type="text" size="40" name="val" value=" <?php $rand=rand(1,100);?>"
/></td>
<tr>
<td width="600" height="33">Entrez un nombre entre 1 et 100(*)</td>
<td width="236"><input type="text" size="40" name="entier"/></td>
<tr>
<td width="164" height="31"> <A href="projet.php" class="Style3">Recommencer Jeu</A></td>
<td width="236"><input name="Ok" type="submit" value="GO"> <input name="NotOk" type="reset" value="EXIT"/> </td>
</table>
<br /> <br /> <br />
<hr align="center" width="500" />
<p align="center">(*) champ obligatoire</p>



</form>
<?php

$valeur=$_REQUEST['val'];
$saisie=$_REQUEST['entier'];
$i=0;
$j=10;
if ($_POST['Ok']="GO")


{ if(empty ($saisie ))

echo "<span class=\"Style2\"> le champ est obligatoire! </span>" ;

else{
do {

if (($saisie)>($valeur))

{echo "<span class=\"Style2\"> trop grand! les nombres des essais restent sont<\span> ". j=$j-1;
$i=$i+1;
}

elseif (($saisie)<($valeur))
{
echo "<span class=\"Style2\"> trop petit! les nombres des essais restent sont<\span> ". j=$j-1;

$i=$i+1;


}



elseif(($saisie)==($valeur))

echo "<span class=\"Style2\"> BRAVO! vous avez devinez </span>".$i."essais";

else

echo"<span class=\"style2\">DESOLE ! Le Jeu est terminer Vous avez depasse le nombrmaximumd'essais> </span>";

}

while ( ($i<10)&&($saisie!=$valeur) );
}}
?>
</body>
</html>

2 réponses

gigaga Messages postés 2346 Date d'inscription vendredi 20 juin 2008 Statut Membre Dernière intervention 22 août 2014 301
8 déc. 2009 à 14:25
Il faut affiché le nombre aléatoire généré :
<?php $rand=rand(1,100); echo $rand;?>


Ensuite si ton formulaire a pour méthode "POST", tu dois récupérer tes variables en POST :
$valeur=$_POST['val'];
$saisie=$_POST['entier']; 
0
gigaga Messages postés 2346 Date d'inscription vendredi 20 juin 2008 Statut Membre Dernière intervention 22 août 2014 301
10 déc. 2009 à 20:33
De rien...
0