2
私は、ロック、ペーパー、はさみをHTMLとPHPを使って10ラウンドで作っていました。私が遭遇した唯一の問題は、$player
,$comp
、および$round
は増加せず、常に初期値になります。何が問題なのでしょうか?PHP:変数がインクリメントしない
これは、PHPの一部のために私のコードです:
<?php session_start();
if(!isset($_SESSION['use']))
{
header("Location:enter.php");
}
if (isset($_GET['logout'])) {
session_destroy();
unset($_SESSION['username']);
header("location: enter.php");
}
$Computer='none';
$user_choice='';
$judgelose = array();
$judgewin = array();
$judgedraw = array();
$round=1;
$player=0;
$comp=0;
if(isset ($_POST['choice']))
{
$Choosefrom= array('Rock', 'Paper', 'Scissors');
$Choice= rand(0,2);
$Computer=$Choosefrom[$Choice];
$user_choice=$_POST['choice'];
if($user_choice == $Computer){
array_push($judgedraw, 'Result : Draw');
}
else if($user_choice == 'Rock' && $Computer == 'Scissors' || $user_choice == 'Scissors' && $Computer == 'Paper' || $user_choice == 'Paper' && $Computer == 'Rock'){
array_push($judgewin, 'Result : Win');
$player++;
}
else if($user_choice == 'Rock' && $Computer == 'Paper' || $user_choice == 'Scissors' && $Computer == 'Rock' || $user_choice == 'Paper' && $Computer == 'Scissors'){
array_push($judgelose, 'Result : Lose');
$comp++;
}
}
?>
これらの値をセッションに保存する必要があります。リセットするページを読み込むたびにセッションに保存する必要があります。 –
Jonが正しいです、あなたのコメントを答えにする必要があります... – Theyouthis