Php 如何调用上一页';将随机值添加到另一页?

Php 如何调用上一页';将随机值添加到另一页?,php,forms,Php,Forms,伙计们,这是我的主页 <?php $random = rand(4, 5); $random2 = rand(1, 12); $random3 = rand(1, 60); $random4 = rand(1, 60); $random5 = rand(1, 60); if ($random2 % 4 != 0) { $random2 += 4 - ($random2 % 4); $call = $random; } else { $random2 += 4 - ($random2 %

伙计们,这是我的主页

<?php
$random = rand(4, 5);
$random2 = rand(1, 12);
$random3 = rand(1, 60);
$random4 = rand(1, 60);
$random5 = rand(1, 60);

if ($random2 % 4 != 0) {
$random2 += 4 - ($random2 % 4);
$call = $random;
} else {
$random2 += 4 - ($random2 % 4);
$call = $random2;
}

$answer = $random * $random2;
?>

<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="CSS/main.css" type="text/css"/>
    <link rel="stylesheet" href="CSS/easy2.css" type="text/css"/>

    <title> Easy Game 2 </title>
<center>
    <h1> Easy Game 2 </h1>
    <h2> Multiple Choice! </h2>
    <div class="border_solid">
        <div id="timer"></div>
    </div>
    <hr>
</center>
</head>
<body>
<form method="post" action="doeasygame2.php">
    <table cellspacing="40" class="table">
        <tr>
            <td>
                <label for="question_1"><?php echo $random; ?> X <?php echo $random2; ?> =?</label>
                <input type="radio" id="mcq" name="mcq" value="<?php echo $random3; ?>"><?php echo $random3; ?>
                <input type="radio" id="mcq" name="mcq" value="<?php echo $random4; ?>"><?php echo $random4; ?>
                <input type="radio" id="mcq" name="mcq" value="<?php echo $random5; ?>"><?php echo $random5; ?>
                <input type="radio" id="mcq" name="mcq" value="<?php echo $answer; ?>"><?php echo $answer; ?>
            </td>
            <td>
                <input type="submit" class="submit" value="submit" name="submit"/><br>
            </td>
        </tr>
    </table>
</form>
</body>
<script type="text/javascript">
var myVar = setInterval(function () {
    myTimer()
}, 1000);
var d = 0;

function myTimer() {
    document.getElementById("timer").innerHTML = d++;
}

</script>
</html>

简单游戏2
简单游戏2
多选!

X=? 简单游戏2 简单游戏2 多选!
X=?
我查看了您的代码,发现您没有在第一页中存储选项,当您尝试在下一页上发布它时,它将变为零,因为所有单选按钮都具有相同的名称,并且当您在下一页上发布它时,它将只发布所选的单选值

为了满足您的要求,您只需使用以下我的代码作为第一页:

<?php
$random = rand(4, 5);
$random2 = rand(1, 12);
$random3 = rand(1, 60);
$random4 = rand(1, 60);
$random5 = rand(1, 60);

if ($random2 % 4 != 0) {
$random2 += 4 - ($random2 % 4);
$call = $random;
} else {
$random2 += 4 - ($random2 % 4);
$call = $random2;
}

$answer = $random * $random2;
?>

<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="CSS/main.css" type="text/css"/>
    <link rel="stylesheet" href="CSS/easy2.css" type="text/css"/>

    <title> Easy Game 2 </title>
<center>
    <h1> Easy Game 2 </h1>
    <h2> Multiple Choice! </h2>
    <div class="border_solid">
        <div id="timer"></div>
    </div>
    <hr>
</center>
</head>
<body>
<form method="post" action="doeasygame2.php">
<table cellspacing="40" class="table">
        <tr>
            <td>
                <label for="question_1"><?php echo $random; ?> X <?php echo $random2; ?> =?</label>
                <input type="radio" id="mcq" name="mcq" value="<?php echo $random3; ?>"><?php echo $random3; ?>
                <input type="radio" id="mcq" name="mcq" value="<?php echo $random4; ?>"><?php echo $random4; ?>
                <input type="radio" id="mcq" name="mcq" value="<?php echo $random5; ?>"><?php echo $random5; ?>
                <input type="radio" id="mcq" name="mcq" value="<?php echo $answer; ?>"><?php echo $answer; ?>
            </td>
            <td>
                <input type="submit" class="submit" value="submit" name="submit"/><br>
            </td>
        </tr>
    </table>
    <input type="hidden" name="random" value="<?php print $random ?>">
    <input type="hidden" name="random2" value="<?php print $random2 ?>">
    <input type="hidden" name="random3" value="<?php print $random3 ?>">
    <input type="hidden" name="random4" value="<?php print $random4 ?>">
    <input type="hidden" name="random5" value="<?php print $random5 ?>">
    <input type="hidden" name="answer" value="<?php print $answer ?>">
</form>
</body>
<script type="text/javascript">
var myVar = setInterval(function () {
    myTimer()
}, 1000);
var d = 0;

function myTimer() {
    document.getElementById("timer").innerHTML = d++;
}

</script>
</html>

简单游戏2
简单游戏2
多选!

X=?
我查看了您的代码,发现您没有在第一页中存储选项,当您尝试在下一页上发布它时,它将变为零,因为所有单选按钮都具有相同的名称,并且当您在下一页上发布它时,它将只发布所选的单选值

为了满足您的要求,您只需使用以下我的代码作为第一页:

<?php
$random = rand(4, 5);
$random2 = rand(1, 12);
$random3 = rand(1, 60);
$random4 = rand(1, 60);
$random5 = rand(1, 60);

if ($random2 % 4 != 0) {
$random2 += 4 - ($random2 % 4);
$call = $random;
} else {
$random2 += 4 - ($random2 % 4);
$call = $random2;
}

$answer = $random * $random2;
?>

<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="CSS/main.css" type="text/css"/>
    <link rel="stylesheet" href="CSS/easy2.css" type="text/css"/>

    <title> Easy Game 2 </title>
<center>
    <h1> Easy Game 2 </h1>
    <h2> Multiple Choice! </h2>
    <div class="border_solid">
        <div id="timer"></div>
    </div>
    <hr>
</center>
</head>
<body>
<form method="post" action="doeasygame2.php">
<table cellspacing="40" class="table">
        <tr>
            <td>
                <label for="question_1"><?php echo $random; ?> X <?php echo $random2; ?> =?</label>
                <input type="radio" id="mcq" name="mcq" value="<?php echo $random3; ?>"><?php echo $random3; ?>
                <input type="radio" id="mcq" name="mcq" value="<?php echo $random4; ?>"><?php echo $random4; ?>
                <input type="radio" id="mcq" name="mcq" value="<?php echo $random5; ?>"><?php echo $random5; ?>
                <input type="radio" id="mcq" name="mcq" value="<?php echo $answer; ?>"><?php echo $answer; ?>
            </td>
            <td>
                <input type="submit" class="submit" value="submit" name="submit"/><br>
            </td>
        </tr>
    </table>
    <input type="hidden" name="random" value="<?php print $random ?>">
    <input type="hidden" name="random2" value="<?php print $random2 ?>">
    <input type="hidden" name="random3" value="<?php print $random3 ?>">
    <input type="hidden" name="random4" value="<?php print $random4 ?>">
    <input type="hidden" name="random5" value="<?php print $random5 ?>">
    <input type="hidden" name="answer" value="<?php print $answer ?>">
</form>
</body>
<script type="text/javascript">
var myVar = setInterval(function () {
    myTimer()
}, 1000);
var d = 0;

function myTimer() {
    document.getElementById("timer").innerHTML = d++;
}

</script>
</html>

简单游戏2
简单游戏2
多选!

X=?
但是我确实在单选按钮下放了一个名字叫mcq,为什么不出来?但是我在单选按钮下放了一个名字叫mcq,为什么不出来?有没有办法在do页面上显示选中的单选按钮@如果你对我的答案感到满意,那么请把我的答案更正。谢谢。请将第二页上的“”替换为“”。以上评论是否对您有帮助?我应该将其放在哪一页?如果我把它放在do页面上,我需要为所有输入做什么?因为如果用户检查另一个单选按钮呢@有没有办法在do页面上显示选中的单选按钮@如果你对我的答案感到满意,那么请把我的答案更正。谢谢。请将第二页上的“”替换为“”。以上评论是否对您有帮助?我应该将其放在哪一页?如果我把它放在do页面上,我需要为所有输入做什么?因为如果用户检查另一个单选按钮呢@沙拉德索尼酒店
<?php

$random = isset($_POST['random']) ? intval($_POST['random']) : 0;
$random2 = isset($_POST['random2']) ? intval($_POST['random2']) : 0;
$random3 = isset($_POST['random3'])? intval($_POST['random3']) : 0;
$random4 = isset($_POST['random4'])? intval($_POST['random4']) : 0;
$random5 = isset($_POST['random5'])? intval($_POST['random5']) : 0;
$answer = isset($_POST['answer'])? intval($_POST['answer']) : 0;
$mcq = $_POST['mcq'];
?>

<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" href="CSS/main.css" type="text/css"/>
    <link rel="stylesheet" href="CSS/easy2.css" type="text/css"/>

    <title> Easy Game 2 </title>
<center>
    <h1> Easy Game 2 </h1>
    <h2> Multiple Choice! </h2>
    <hr>
</center>
</head>
<body>
<table cellspacing="40" class="table">
    <tr>
        <td>
            <label for="question_1"><?php echo $random; ?> X <?php echo $random2; ?> =?</label>
            <input type="radio" id="mcq" name="mcq" value="<?php echo $random3; ?>" <?php print $random3 == $mcq ? 'checked="checked"' : '' ?> ><?php echo $random3; ?>
            <input type="radio" id="mcq" name="mcq" value="<?php echo $random4; ?>" <?php print $random4 == $mcq ? 'checked="checked"' : '' ?> ><?php echo $random4; ?>
            <input type="radio" id="mcq" name="mcq" value="<?php echo $random5; ?>" <?php print $random5 == $mcq ? 'checked="checked"' : '' ?> ><?php echo $random5; ?>
            <input type="radio" id="mcq" name="mcq" <?php print $mcq == $answer ? 'checked="checked"' : '' ?> ><?php echo $answer; ?>
            <?php
            if ($mcq == $answer) {
                echo "Correct!";
            } else {
                echo "Wrong!";
            }
            ?>
        </td>
    </tr>
</table>
</body>
</html>