나는 PHP에서 초급 해요. 나는 기본적인 숫자 추측 게임을 만들고있다. 2 단계가 있습니다. level1.php
에서 나는 지금은 레벨 2에 선수를 보낼 값이숨겨진 값을 확인하는 방법
<?php
session_start();
if (!isset($_SESSION['wins']) || !isset($_SESSION['losses'])) {
$_SESSION['wins'] = 0;
$_SESSION['losses'] = 0;
}
$random = rand(1, 5);
if ($_POST["firstdata"] == $random){
$_SESSION['wins']++;
echo "<h1><font color=\"green\">Congrulations!</h1></font><br>";
else{
$_SESSION['losses']++;
echo "<h1><font color=\"red\">Nope wrong answer</h1></font><br>";
(내가 다른 코드를 생략) 맞다면 내가 확인 formprocess.php
에 formprocess.php
echo "<form name = \"myfirstform\" action = \"formprocess.php\" method = \"POST\">";
echo "Enter Integer Between 1-5<br>";
echo "<input type = \"text\" name = \"firstdata\">";
echo "<br> <input type= \"submit\" value = \"submit\">";
echo "</form>";
에 대한 사용자 입력을 보내 그의 대답이 맞다면 .php. 나는이 같은 숨겨진 입력 함께 할 것을 시도 :
echo "<form name = \"mysecondform\" action = \"level2.php\" method = \"POST\">";
echo " <input type=\"hidden\" name=\"seconddata\" value=\"1\">";
echo "<br> <input type= \"submit\" value = \"Go to Level2\">";
level2.php
에서 내 코드는 다음과 같습니다 대답은 정확하더라도
<?php
if ($_POST["seconddata"] == 1){
echo "<html><head><title>Calculator Game From 1998</title></head><body>";
echo "<h1>Please Guess The Answer-Level2</h1>";
echo "<form name = \"myfirstform\" action = \"formprocess.php\" method = \"POST\">";
echo "Enter Integer Between 1-10<br>";
echo "<input type = \"text\" name = \"firstdata\">";
echo "<br> <input type= \"submit\" value = \"submit\">";
echo "</form>";
echo "</body></html>";
}
else{
echo "You didn't finish level1"
}
?>
,이 페이지에서 아무 것도 없다. "1"
이 (가) 다시 작동하지 않는 1
값을 변경했습니다.
내가 당신의 빈 페이지가 표시되면
else{
echo "You didn't finish level1"
}
전체 코드를 게시하고 js 오류가있는 경우 개발자 도구를 확인하십시오. error_reporting을 입력하십시오. –
print_r ($ _ POST)는 level2.php에서 무엇을 말합니까? –