Dice roll problem
Posted: Tue Oct 04, 2011 7:36 pm
Hi guys, first post here
Looks like im going to be here alot, since im taking a PHP course and im quite lost.
Anyways, im having trouble with this code. I think its the way i assigned my variables. Basically i need to make a program that he user inputs a number from 1-6 and a die is rolled and an image is displayed. If the user input the correct number shown on the die, they are awarded one point (this is to be done with session variables which i havent a clue how to do them correctly.
Anything will help.
Heres the form:
<body>
<form name = "n" action="diceroll.php" method="post">
Enter your roll: <br>
<input type= "text" name="1">
<input type ="submit" name = "submit">
</form>
</body>
and the PHP:
Looks like im going to be here alot, since im taking a PHP course and im quite lost.
Anyways, im having trouble with this code. I think its the way i assigned my variables. Basically i need to make a program that he user inputs a number from 1-6 and a die is rolled and an image is displayed. If the user input the correct number shown on the die, they are awarded one point (this is to be done with session variables which i havent a clue how to do them correctly.
Anything will help.
Heres the form:
<body>
<form name = "n" action="diceroll.php" method="post">
Enter your roll: <br>
<input type= "text" name="1">
<input type ="submit" name = "submit">
</form>
</body>
and the PHP:
Code: Select all
<body>
<?php
$WIN = $_POST['guess'];
$dice = rand(1, 6);
if ($WIN == $dice){
echo "You Guessed Correctly!";
}else {
echo "You have Guesed Incorrectley". "<br>";
}
if($dice == 1) echo "<img src='dice1.png'>"."<br>";
if($dice == 2) echo "<img src='dice2.png'>"."<br>";
if($dice == 3) echo "<img src='dice3.png'>"."<br>";
if($dice == 4) echo "<img src='dice4.png'>"."<br>";
if($dice == 5) echo "<img src='dice5.png'>"."<br>";
if($dice == 6) echo "<img src='dice6.png'>"."<br>";
//else {
//echo "You have Guesed Incorrectley". "<br>";
//}
?>
<form name= "back" action= "diceroll.html" method= "post">
<input type="submit" name="back" value ="Play Again">
</form>
</body>