我试图在页面之间传递变量,我失败了

时间:2016-07-28 10:36:19

标签: php html

我一直在尝试在页面之间传递一个变量,以便在测验中计算得分,由于某种原因,变量没有像我想要的那样在页面之间传递,我希望得分为1第一个按钮被击中,如果击中第二个按钮则为2,截至目前,我点击结果的总是0。

第一页 - 减去一整套样式:

Private Sub CB2_Click()
erow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).Row
'Cells(erow, 1) ??? to get auto numbering starting from A2 (number 1,2,3,etc)
Cells(erow, 2) = TB1.Text
Cells(erow, 3) = TB2.Text
Cells(erow, 4) = TB3.Text
Cells(erow, 5) = TB4.Text
End Sub

这是完整的第二页:

<?PHP

$Score=0;

if ( isset( $_POST['Submit1'] ) ) { 
    $Score=$Score+1;
}

if ( isset( $_POST['Submit2'] ) ) { 
    $Score=$Score+2;
}

?>

<body>

<center><img src="http://fc06.deviantart.net/fs70/f/2011/002/d/3/purple_blob_pet_by_bunni0222-d36aw4q.png" alt="" align="middle"/></center>

<FORM NAME ="form1" METHOD ="POST" ACTION ="Test1.php">

<INPUT TYPE = "Hidden" Name = "h1" Value = <?PHP echo $Score; ?> >
<center><INPUT TYPE = "Submit" class=myButton Name = "Submit1" VALUE = "1"></center>
<center><INPUT TYPE = "Submit" class=myButton Name = "Submit2" VALUE = "2"></center>

</FORM>


</body>

我会很感激帮助,如果它是愚蠢的我道歉我只是在学习如何编写HTML和PHP。

3 个答案:

答案 0 :(得分:0)

我认为问题在于这一行:

<INPUT TYPE = "Hidden" Name = "h1" Value = <?PHP echo $Score; ?> >

<INPUT TYPE = "Hidden" Name = "h1" Value = "<?PHP echo $Score; ?>" >

答案 1 :(得分:0)

将您的第一页php代码放在第二页php的顶部。它会工作..

第一页将是

<body>
<center><img src="http://fc06.deviantart.net/fs70/f/2011/002/d/3/purple_blob_pet_by_bunni0222-d36aw4q.png" alt="" align="middle"/></center>
<FORM NAME ="form1" METHOD ="POST" ACTION ="Test1.php">
<INPUT TYPE = "Hidden" Name = "h1" Value = <?PHP echo $Score; ?> >
<center><INPUT TYPE = "Submit" class=myButton Name = "Submit1" VALUE = "1"></center>
<center><INPUT TYPE = "Submit" class=myButton Name = "Submit2" VALUE = "2"></center>
</FORM>
</body>

,第二页将是

<html>
  <head>
    <title>Test</title>
  </head>
  <body>
    <p>
      <?php
        $Score=0;
if ( isset( $_POST['Submit1'] ) ) { 
    $Score=$Score+1;
}

if ( isset( $_POST['Submit2'] ) ) { 
    $Score=$Score+2;
}
        $Score = $_POST['h1'];
        echo $Score; ?>
    </p>
  </body>
</html>

答案 2 :(得分:0)

FirstPage.php应该如下所示。

<body>

    <FORM NAME ="form1" METHOD ="POST" action="SecondPage.php">
        <center><input TYPE = "Submit"  name = "Submit1" VALUE = "1"></center>
        <center><input TYPE = "Submit" name = "Submit1" VALUE = "2"></center>
    </FORM>

</body>

SecondPage.php应该喜欢这个

<body>
    <p>
      <?php
            $Score=0;   

            if ( isset( $_POST['Submit1'] ) ) { 
                $Score=$_POST['Submit1'];   
            }
            echo $Score; 
      ?>
    </p>
</body>