Estoy intentando crear un juego en el que hay 4 jugadores y un dado con html y php. El problema es que al hacer clic en el dado (que es un input type=image) vuelve a cargar el script y vuelve a iniciar las variables, $contadorjugador, a 0. Da igual que el random del dado se sume al contador que se volverá a iniciar a 0. Os paso el archivo html y php para que me ayudéis un poco porque estoy perdido. Muchas gracias.
HTML:
Código HTML:
Ver original
<html> <head> <META charset="UTF-8"> </head> <body bgcolor="#FE9A2E"> <form action="BochoGame.php" method="post"> <br> <center> Jugador 1:<input type="text" name="jugador1" required> Jugador 2:<input type="text" name="jugador2" required> Jugador 3:<input type="text" name="jugador3" required> <br> <input type="submit" value="Enviar" name="send"> </center> </form> </body </html>
PHP:
Código PHP:
Ver original
<html> <head> <meta charset="UTF-8"> <title>BochoGame</title> </head> <form method="post"> <body bgcolor="#FE9A2E"> <table border="3" bordercolor="black" width="100%"> <tr> <td rowspan="2" width="20%" valign="top"> <center><font size="7"><b><u>Jugadores</u></b></font><br></center> <?php $_SESSION['primero'] = $_POST['jugador1']; $jugador1 = $_POST['jugador1']; $_SESSION['segundo'] = $_POST['jugador2']; $jugador2 = $_POST['jugador2']; $_SESSION['tercero'] = $_POST['jugador3']; $jugador3 = $_POST['jugador3']; $_SESSION['cuarto'] = $_POST['jugador4']; $jugador4 = $_POST['jugador4']; } else { $jugador1 = $_SESSION['primero']; $jugador2 = $_SESSION['segundo']; $jugador3 = $_SESSION['tercero']; $jugador4 = $_SESSION['cuarto']; } $contadorjugador1 = 0; $contadorjugador2 = 0; $contadorjugador3 = 0; $contadorjugador4 = 0; echo"<center><h1><b>".$jugador1 . "= " . $contadorjugador1 . "</b></h1></center><br>"; echo"<center><h1><b>". $jugador2 . "= " . $contadorjugador2 . "</b></h1></center><br>"; echo"<center><h1><b>". $jugador3 . "= " . $contadorjugador3 . "</b></h1></center><br>"; echo"<center><h1><b>". $jugador4 . "= " . $contadorjugador4."</b></h1></center>"; ?> </td> <td rowspan="2" width="40%" valign="top"> <center><font size="7"><b><u>Dado</u></b></font><br></center> <br> <center><input type="image" value="randomdado" name="dado" src="Fotos/dado.png" width="50%"></center> <br> <?php switch ($randado) { case 1: echo "<center><img src='Fotos/1.png' width='30%'></center>"; $contadorjugador1++; break; case 2: echo "<center><img src='Fotos/2.png' width='30%'></center>"; break; case 3: echo "<center><img src='Fotos/3.png' width='30%'></center>"; break; case 4: echo "<center><img src='Fotos/4.png' width='30%'></center>"; break; case 5: echo "<center><img src='Fotos/5.png' width='30%'></center>"; break; case 6: echo "<center><img src='Fotos/6.png' width='30%'></center>"; break; } } ?> </td> <td> </td> </tr> <tr> <td> </td> </tr> </table> </form> </body> </html>