【问题标题】:Why can i not echo out these variables?为什么我不能回显这些变量?
【发布时间】:2014-01-03 11:17:17
【问题描述】:

以下代码允许用户插入 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>}

【问题讨论】:

    标签: php variables if-statement input echo


    【解决方案1】:

    UPNProject 文本框不在 &lt;form&gt; tag 内。将它们放在表单标签内。

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        试试

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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-02-03
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多