在php中提交表单后如何保留在文本框中输入的数据?

发布于 2024-12-10 05:47:09 字数 2931 浏览 0 评论 0原文

我想在提交表单后保留在表单文本框中输入的数据。我仅对第一个文本框执行此操作以测试功能“VALUE =“””,但是当我填写文本框并提交表单时,文本框中会出现一个通知错误,其中显示“
注意:未定义变量:/web/stud/u0867587/MOBILEPHP/exam_interface.php中的sessionid,第13
行”。当我在互联网上查看如何正确执行此操作时,所有州都按照我的方式执行。那么为什么它不起作用,你能帮我解决这个问题吗?

代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Exam Interface</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<p><strong>NOTE: </strong>If a search box is left blank, then the form will search for all data under that specific field</p>

<form action="exam_interface.php" method="post" name="sessionform">        <!-- This will post the form to its own page"-->
<p>Session ID: <input type="text" name="sessionid" value="<?PHP print $sessionid ; ?>" /></p>      <!-- Enter Session Id here-->
<p>Module Number: <input type="text" name="moduleid" /></p>      <!-- Enter Module Id here-->
<p>Teacher Username: <input type="text" name="teacherid" /></p>      <!-- Enter Teacher here-->
<p>Student Username: <input type="text" name="studentid" /></p>      <!-- Enter User Id here-->
<p>Grade: <input type="text" name="grade" /></p>      <!-- Enter Grade here-->
<p>Order Results By: <select name="order">
<option value="ordersessionid">Session ID</option>
<option value="ordermoduleid">Module Number</option>
<option value="orderteacherid">Teacher Username</option>
<option value="orderstudentid">Student Username</option>
<option value="ordergrade">Grade</option>
</select>
<p><input type="submit" value="Submit" name="submit" /></p>
</form>

<?php

$username="xxx";
$password="xxx";
$database="mobile_app";

mysql_connect('localhost',$username,$password);

@mysql_select_db($database) or die("Unable to select database");

if(isset($_POST['submit'])) {

$sessionid = isset ($_POST['sessionid']) ? $_POST['sessionid'] : "";
$moduleid = isset ($_POST['moduleid']) ? $_POST['moduleid'] : "";
$teacherid = isset ($_POST['teacherid']) ? $_POST['teacherid'] : "";
$studentid = isset ($_POST['studentid']) ? $_POST['studentid'] : "";
$grade = isset ($_POST['grade']) ? $_POST['grade'] : "";
$orderfield = isset ($_POST['order']) ? $_POST['order'] : "";

$sessionid = mysql_real_escape_string($sessionid);
$moduleid = mysql_real_escape_string($moduleid);
$teacherid = mysql_real_escape_string($teacherid);
$studentid = mysql_real_escape_string($studentid);
$grade = mysql_real_escape_string($grade);

 ?>

</body>
</html>

请帮忙,谢谢。

I want to keep the data inputted in a text box in my form after the form has been submitted. I have done it only for the first text box to test the function "VALUE=""" but when I fill in the text box and submit the form then a notice error appears in the text box which says "
Notice: Undefined variable: sessionid in /web/stud/u0867587/MOBILEPHP/exam_interface.php on line 13
". When I look on the internet to see how to do it properly it all states do it the way I have done. So why is it not working and can you please help me with this problem.

Below is the code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Exam Interface</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>

<p><strong>NOTE: </strong>If a search box is left blank, then the form will search for all data under that specific field</p>

<form action="exam_interface.php" method="post" name="sessionform">        <!-- This will post the form to its own page"-->
<p>Session ID: <input type="text" name="sessionid" value="<?PHP print $sessionid ; ?>" /></p>      <!-- Enter Session Id here-->
<p>Module Number: <input type="text" name="moduleid" /></p>      <!-- Enter Module Id here-->
<p>Teacher Username: <input type="text" name="teacherid" /></p>      <!-- Enter Teacher here-->
<p>Student Username: <input type="text" name="studentid" /></p>      <!-- Enter User Id here-->
<p>Grade: <input type="text" name="grade" /></p>      <!-- Enter Grade here-->
<p>Order Results By: <select name="order">
<option value="ordersessionid">Session ID</option>
<option value="ordermoduleid">Module Number</option>
<option value="orderteacherid">Teacher Username</option>
<option value="orderstudentid">Student Username</option>
<option value="ordergrade">Grade</option>
</select>
<p><input type="submit" value="Submit" name="submit" /></p>
</form>

<?php

$username="xxx";
$password="xxx";
$database="mobile_app";

mysql_connect('localhost',$username,$password);

@mysql_select_db($database) or die("Unable to select database");

if(isset($_POST['submit'])) {

$sessionid = isset ($_POST['sessionid']) ? $_POST['sessionid'] : "";
$moduleid = isset ($_POST['moduleid']) ? $_POST['moduleid'] : "";
$teacherid = isset ($_POST['teacherid']) ? $_POST['teacherid'] : "";
$studentid = isset ($_POST['studentid']) ? $_POST['studentid'] : "";
$grade = isset ($_POST['grade']) ? $_POST['grade'] : "";
$orderfield = isset ($_POST['order']) ? $_POST['order'] : "";

$sessionid = mysql_real_escape_string($sessionid);
$moduleid = mysql_real_escape_string($moduleid);
$teacherid = mysql_real_escape_string($teacherid);
$studentid = mysql_real_escape_string($studentid);
$grade = mysql_real_escape_string($grade);

 ?>

</body>
</html>

Please help, Thank You.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

看海 2024-12-17 05:47:09

您在检索之前使用$sessionid。将 php 指令放在 html 部分之前。

You are using $sessionid before retriving it. Put your php instructions before the html part.

一紙繁鸢 2024-12-17 05:47:09

将 PHP 代码放在 HTML 文件之前,并将字段的值设置为在发布时捕获它的变量。

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Exam Interface</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>

        <?php
            $username="xxx";
            $password="xxx";
            $database="mobile_app";

            mysql_connect('localhost',$username,$password);

            @mysql_select_db($database) or die("Unable to select database");

            if(isset($_POST['submit'])) {
                $sessionid = isset ($_POST['sessionid']) ? $_POST['sessionid'] : "";
                $moduleid = isset ($_POST['moduleid']) ? $_POST['moduleid'] : "";
                $teacherid = isset ($_POST['teacherid']) ? $_POST['teacherid'] : "";
                $studentid = isset ($_POST['studentid']) ? $_POST['studentid'] : "";
                $grade = isset ($_POST['grade']) ? $_POST['grade'] : "";
                $orderfield = isset ($_POST['order']) ? $_POST['order'] : "";

                $sessionid = mysql_real_escape_string($sessionid);
                $moduleid = mysql_real_escape_string($moduleid);
                $teacherid = mysql_real_escape_string($teacherid);
                $studentid = mysql_real_escape_string($studentid);
                $grade = mysql_real_escape_string($grade);
            }
        ?>
        <p><strong>NOTE: </strong>If a search box is left blank, then the form will search for all data under that specific field</p>

        <form action="test.php" method="post" name="sessionform">        <!-- This will post the form to its own page"-->
            <p>Session ID: <input type="text" name="sessionid" value="<?PHP print $sessionid ; ?>" /></p>      <!-- Enter Session Id here-->
            <p>Module Number: <input type="text" name="moduleid" value="<?PHP print $moduleid ; ?>" /></p>      <!-- Enter Module Id here-->
            <p>Teacher Username: <input type="text" name="teacherid" value="<?PHP print $teacherid ; ?>" /></p>      <!-- Enter Teacher here-->
            <p>Student Username: <input type="text" name="studentid" value="<?PHP print $studentid ; ?>" /></p>      <!-- Enter User Id here-->
            <p>Grade: <input type="text" name="grade" value="<?PHP print $grade ; ?>" /></p>      <!-- Enter Grade here-->
            <p>Order Results By: <select name="order">
            <option value="ordersessionid" <?php if ($orderfield == "ordersessionid") echo 'selected="selected" '; ?>>Session ID</option>
            <option value="ordermoduleid"> <?php if ($orderfield == "ordermoduleid") echo 'selected="selected" '; ?>Module Number</option>
            <option value="orderteacherid" <?php if ($orderfield == "orderteacherid") echo 'selected="selected" '; ?>>Teacher Username</option>
            <option value="orderstudentid" <?php if ($orderfield == "orderstudentid") echo 'selected="selected" '; ?>>Student Username</option>
            <option value="ordergrade" <?php if ($orderfield == "ordergrade") echo 'selected="selected" '; ?>>Grade</option>
            </select>
            <p><input type="submit" value="Submit" name="submit" /></p>
        </form>

    </body>
</html>

Put your PHP code before the HTML file and set the value of the fields to the variable that catches it upon post.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Exam Interface</title>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    </head>
    <body>

        <?php
            $username="xxx";
            $password="xxx";
            $database="mobile_app";

            mysql_connect('localhost',$username,$password);

            @mysql_select_db($database) or die("Unable to select database");

            if(isset($_POST['submit'])) {
                $sessionid = isset ($_POST['sessionid']) ? $_POST['sessionid'] : "";
                $moduleid = isset ($_POST['moduleid']) ? $_POST['moduleid'] : "";
                $teacherid = isset ($_POST['teacherid']) ? $_POST['teacherid'] : "";
                $studentid = isset ($_POST['studentid']) ? $_POST['studentid'] : "";
                $grade = isset ($_POST['grade']) ? $_POST['grade'] : "";
                $orderfield = isset ($_POST['order']) ? $_POST['order'] : "";

                $sessionid = mysql_real_escape_string($sessionid);
                $moduleid = mysql_real_escape_string($moduleid);
                $teacherid = mysql_real_escape_string($teacherid);
                $studentid = mysql_real_escape_string($studentid);
                $grade = mysql_real_escape_string($grade);
            }
        ?>
        <p><strong>NOTE: </strong>If a search box is left blank, then the form will search for all data under that specific field</p>

        <form action="test.php" method="post" name="sessionform">        <!-- This will post the form to its own page"-->
            <p>Session ID: <input type="text" name="sessionid" value="<?PHP print $sessionid ; ?>" /></p>      <!-- Enter Session Id here-->
            <p>Module Number: <input type="text" name="moduleid" value="<?PHP print $moduleid ; ?>" /></p>      <!-- Enter Module Id here-->
            <p>Teacher Username: <input type="text" name="teacherid" value="<?PHP print $teacherid ; ?>" /></p>      <!-- Enter Teacher here-->
            <p>Student Username: <input type="text" name="studentid" value="<?PHP print $studentid ; ?>" /></p>      <!-- Enter User Id here-->
            <p>Grade: <input type="text" name="grade" value="<?PHP print $grade ; ?>" /></p>      <!-- Enter Grade here-->
            <p>Order Results By: <select name="order">
            <option value="ordersessionid" <?php if ($orderfield == "ordersessionid") echo 'selected="selected" '; ?>>Session ID</option>
            <option value="ordermoduleid"> <?php if ($orderfield == "ordermoduleid") echo 'selected="selected" '; ?>Module Number</option>
            <option value="orderteacherid" <?php if ($orderfield == "orderteacherid") echo 'selected="selected" '; ?>>Teacher Username</option>
            <option value="orderstudentid" <?php if ($orderfield == "orderstudentid") echo 'selected="selected" '; ?>>Student Username</option>
            <option value="ordergrade" <?php if ($orderfield == "ordergrade") echo 'selected="selected" '; ?>>Grade</option>
            </select>
            <p><input type="submit" value="Submit" name="submit" /></p>
        </form>

    </body>
</html>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文