为什么我不能回应这些变量?

时间:2014-01-03 11:17:17

标签: php variables if-statement input echo

以下代码允许用户插入7个数字,当点击$ submit时,这些数字的平均值将被计算并打印在屏幕上。

然而,与$ upn和$ project变量(也由用户输入)相关联的值不会在屏幕上打印。

我之前有这个工作,它有如此简单的功能,但无法弄清楚为什么这不会反映$ upn和$ project值。

非常感谢帮助!

道歉,但我无法发布图片,因此代码粘贴在下面。谢谢。

{<?php
$num1 = $_POST['num1'];
$num2 = $_POST['num2'];
$num3 = $_POST['num3'];
$num4 = $_POST['num4'];
$num5 = $_POST['num5'];
$num6 = $_POST['num6'];
$num7 = $_POST['num7'];

$upn = $_POST['pupil'];
$project = $_POST['project'];

$submit = $_POST['submit'];

if ($submit) {

$sum = ($num1 + $num2 + $num3 + $num4 + $num5 + $num6 + $num7) / 7;

echo ("$upn" . "$project" . "$sum ");
    }

?>

<html>
<head>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="UTF-8">
</head>
<body>
    <div id="wrapper">
        <center>             
            <div class="front">
            <h2>Project Assessment</h2>
                    <table class="table" border="0">
                        <tr>
                            <td><span>Enter the correct UPN of the pupil whos project you have     marked.</span></td>
                            <td><input class="input username" type="text" name="pupil"     placeholder="UPN"/></td>
                        </tr>
                        <tr>
                            <td><span>Enter the correct Project Code</span></td>
                            <td><input class="input username" type="text" name="project" placeholder="Project"/></td>
                        </tr>
                    </table>
                        </div>

            <form name="assess-form" class="assess-form" action="calc2.php" method="post">            
                <div class="header">
                    </br><hr/></br>
                    <span>Grade all topic criteria and retrieve the overall project grade.</span>    </br>
                </div>
                <div class="content">
                    <table class="table" border="0">
                        <tr>
                            <td>Research:</td>
                            <td><input class="input username" type="text" name="num1"/></td>
                            <td>Specification:</td>
                            <td><input class="input username" type="text" name="num2"/></td>
                            <td>Ideas:</td>
                            <td><input class="input username" type="text" name="num3"/></td>
                            <td>Development: <input class="input username" type="text"            name="num4"/></td>
                        </tr>
                        <tr>
                            <td>Planning:</td>
                            <td><input class="input username" type="text" name="num5"/></td>
                            <td>Implementation:</td>
                            <td><input class="input username" type="text" name="num6"/></td>
                            <td>Evaluation:</td>
                            <td><input class="input username" type="text" name="num7"/></td>
                            <td><div class="footer"><input type="submit" name='submit' value="Get     Overall Mark" class="button" /></div></td>
                        </tr>
                    </table>
                    </br><hr/></br>
                </div>
                </div> <!-- end wrapper -->
            </form><br/>
            </body>
            </html>}

3 个答案:

答案 0 :(得分:5)

UPNProject文本框不在<form> tag内。将它们放在表格标签内。

答案 1 :(得分:0)

这些输入不包含在表单中。

答案 2 :(得分:-2)

尝试

if (isset($submit)) {
$sum = ($num1 + $num2 + $num3 + $num4 + $num5 + $num6 + $num7) / 7;
echo ("$upn" . "$project" . "$sum ");
}