除了号码更改命令外,该程序工作正常 如果有人能够发现我的错误,那将非常感激 更改表单出现但提交按钮不会POST到变量。
change.php
<form class="" action="index.php" method="post">
<p>Min:<input type="number" name="min" value=""></p>
<p>Max:<input type="number" name="max" value=""></P>
<input type="submit" name="valuechange" value="Change">
</form>
的index.php
<?php session_start();
?>
<center>
<?php
$minn = 1;
$maxx = 3;
if (isset($_GET["change"])) {
if (isset($_POST["valuechange"])) {
$minn = $_POST["min"];
$maxx = $_POST["max"];
}else {
include("change.php");
}
}
echo "<h1>Guess a number between ". $minn ." and ". $maxx . "</h1>";
if (!isset($_SESSION["number"])) {
$_SESSION["number"] = mt_rand($minn,$maxx);
$_SESSION["counter"] = 0;
}
if (isset($_POST["guess"])) {
if ($_POST['guess']== $_SESSION['number']) {
echo "<br><br><br><br>Correct<br>"."Your number was ". $_SESSION["number"]."<br>"."<a href='reset.php'>Play Again </a>";
session_destroy();
echo "<br><a href='index.php?change=true'>Change Numbers</a>";
}else {
$_SESSION["counter"] = $_SESSION["counter"] + 1;
include("form.php");
echo $_SESSION["counter"]. " Guesses<br>";
if ($_POST["guess"] > $_SESSION["number"]) {
echo "Incorrect your number is too big try a smaller number.";
} else if ($_POST["guess"] < $_SESSION["number"]) {
echo "Incorrect your number is too small try a larger number.";
}
echo "<br><a href='reset.php'>RESET </a>";
}
}else {
include("form.php");
}
?>
</center>