I need to create 2 php pages 1php This page should recreate
I need to create 2 php pages.
1.php
This page should recreate the game of “Rock Paper Scissors”. It should have three radio buttons on it: “Rock”, “Paper”, and “Scissors” and also a “Submit” button. When the user clicks submit, it should submit their choice to 2.php.
2.php
This file should randomly pick “Rock”, “Paper”, or “Scissors” as the CPUs selection. It should then display the results of the game. Example output would be “Player: Rock. CPU: Scissors. Result: Win”. If the user didn’t submit a choice, an error should be displayed.
Solution
1.php
<?php
echo \'<form action=\"2.php\" method=\"post\" />
<input type=\"radio\" name=\"user_choice\" value=\"Rock\" title=\"Rock\" /> <br /><br />
<input type=\"radio\" name=\"user_choice\" value=\"Paper\" title=\"Paper\" /> <br /><br />
<input type=\"radio\" name=\"user_choice\" value=\"Scissors\" title=\"Scissors\" /> <br /><br />
</form> \';
?>
2.php
<?php
IF($_POST[\'user_choice\']){
$user_choice = $_POST[\'user_choice\'];
$Choosefrom= array(Rock, Paper, Scissors);
$Choice= rand(0,2);
$Computer=$Choosefrom[$Choice];
IF($user_choice == $Computer){
echo \'Player: \'.$user_choice.\' CPU: \'.$Computer.\'. Result: Win\';
}
ELSE {
echo \'Player: \'.$user_choice.\' CPU: \'.$Computer.\'. Result: Lose\';
}
}
?>
