0

我需要一些关于小型 php 脚本的帮助。我想将我的 $score 传递给另一个 URL。

访问者通过 html POST 表单提交测试后,将被带到计算并显示测试分数的页面:

<?php
$answer1= $_POST['answer1'];
$answer2= $_POST['answer2'];
$answer5= $_POST['answer5'];
$answer6= $_POST['answer6'];
$answer7= $_POST['answer7'];
$answer8= $_POST['answer8'];
$answer9= $_POST['answer9'];
$answer10= $_POST['answer10'];
$answer11= $_POST['answer11'];
$answer12= $_POST['answer12'];
$answer13= $_POST['answer13'];
$answer14= $_POST['answer14'];
$answer15= $_POST['answer15'];
$answer16= $_POST['answer16'];
$answer17= $_POST['answer17'];
$answer18= $_POST['answer18'];
$answer19= $_POST['answer19'];
$answer20= $_POST['answer20'];
$score = 0;

if ($answer1 == "A"){$score++;$score++;$score++;$score++;$score++;}
if ($answer1 == "B"){$score++;$score++;$score++;$score++;}


if ($answer5 == "A"){$score++;$score++;$score++;$score++;$score++;}

if ($answer6 == "A"){$score++;}
if ($answer6 == "B"){$score++;$score++;$score++;$score++;$score++;}

if ($answer7 == "A"){$score++;}
if ($answer7 == "B"){$score++;$score++;$score++;}
if ($answer7 == "C"){$score++;$score++;$score++;$score++;$score++;$score++;}

if ($answer8 == "A"){$score++;$score++;$score++;$score++;$score++;}
if ($answer8 == "B"){$score++;}
if ($answer8 == "C"){$score++;$score++;}


if ($answer9 == "B"){$score++;$score++;$score++;$score++;}
if ($answer9 == "C"){$score++;$score++;$score++;$score++;$score++;$score++;$score++;}
if ($answer9 == "D"){$score++;$score++;$score++;$score++;$score++;$score++;$score++;$score++;$score++;$score++;$score++;$score++;$score++;$score++;}

if ($answer10 == "A"){$score++;$score++;$score++;}
if ($answer10 == "B"){$score++;$score++;$score++;$score++;$score++;$score++;}
if ($answer10 == "C"){$score++;$score++;$score++;$score++;$score++;$score++;$score++;$score++;$score++;$score++;}

if ($answer11 == "A"){$score++;}
if ($answer11 == "B"){$score++;$score++;$score++;$score++;$score++;}
if ($answer11 == "C"){$score++;$score++;$score++;}


if ($answer12 == "B"){$score++;$score++;$score++;$score++;$score++;}
if ($answer12 == "C"){$score++;$score++;$score++;}

if ($answer13 == "A"){$score++;$score++;$score++;$score++;$score++;}
if ($answer13 == "B"){$score++;}

if ($answer14 == "A"){$score++;$score++;$score++;}
if ($answer14 == "B"){$score++;$score++;$score++;$score++;$score++;}
if ($answer14 == "C"){$score++;}

if ($answer15 == "A"){$score++;}
if ($answer15 == "C"){$score++;$score++;$score++;}
if ($answer15 == "D"){$score++;$score++;$score++;$score++;$score++;}

if ($answer16 == "B"){$score++;}
if ($answer16 == "C"){$score++;$score++;}
if ($answer16 == "D"){$score++;$score++;$score++;$score++;$score++;}

if ($answer17 == "B"){$score++;}
if ($answer17 == "C"){$score++;$score++;}
if ($answer17 == "D"){$score++;$score++;$score++;$score++;$score++;}

if ($answer18 == "B"){$score++;$score++;$score++;$score++;}
if ($answer18 == "C"){$score++;$score++;}
if ($answer18 == "E"){$score++;$score++;$score++;$score++;$score++;}
if ($answer18 == "F"){$score++;$score++;$score++;}

if ($answer19 == "B"){$score++;$score++;$score++;$score++;$score++;}
if ($answer20 == "A"){$score++;$score++;$score++;$score++;$score++;}

echo "$score";

?> 

在那个页面上, echo "$score"; 显示时,访问者必须单击此表单按钮才能激活服务:

<form name="form1" method="post" action="test.php">

<input name="pass" type="text" id="pass" />

<input type="submit" style="font-weight:bold" name="Submit" value="Aktiviraj!" />        </form>

单击按钮后,他们将被带到另一个 .html 页面,我实际上想要测试 echo "$score"; 再次显示。基本上我希望页面 A 将 echo $ score 传递(发送)到页面 B,而不涉及过程中的 MySql 基础。

提前致谢。

4

2 回答 2

0
<input name='answer[0]'/>
<input name='answer[1]'/>
<input name='answer[2]'/>
<input name='answer[3]'/>
<input name='answer[4]'/>

<?php
session_start();
$_SESSION['score'] = 0;
//If you aren't using a DB backend
$answers = array(
    0 => array("A"=>4,"B"=>1),
    1 => array("A"=>4,"B"=>1),
    2 => array("A"=>4,"B"=>2,"C"=>0),//and so on

);
foreach ($_POST['answer'] as $key => $value)
{
    $_SESSION['score'] += (int)$answers[$key][$value];
}
?>
于 2013-02-17T17:00:30.387 回答
0

您应该使用会话在请求之间传输您的计算值。

于 2013-02-17T17:19:41.913 回答