如何检查隐藏价值

时间:2014-11-30 16:56:08

标签: php forms

我是php的初学者。我正在做一个基本的猜数游戏。有2个级别。在level1.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>";

formprocess.php我检查值是否正确

<?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>";

它工作得很好(我跳过其他代码)现在我想将播放器发送到level2.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"无效。有什么问题

2 个答案:

答案 0 :(得分:1)

如果您的页面显示为空白可能是因为php错误,请将下一个代码放在php脚本的顶部

error_reporting(E_ALL); 
ini_set("display_errors", 1); 

答案 1 :(得分:0)

愚蠢的错误

我应该写

echo "You didn't finish level1"

而不是

else{
echo "You didn't finish level1"
}