我希望在提交表单后将数据保存在表单的文本框中。我只在第一个文本框中测试函数“VALUE =”“”,但是当我填写文本框并提交表单时,文本框中会出现一个通知错误,上面写着“
注意:未定义的变量: /web/stud/u0867587/MOBILEPHP/exam_interface.php 中 13 <“的会话ID。当我在网上看到如何正确地做到这一点时,所有州都按照我的方式去做。那么为什么它不起作用,请你帮我解决这个问题。
以下是代码:
<!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>
请帮助,谢谢。
答案 0 :(得分:0)
您正在使用$sessionid
重新审核之前。把你的PHP指令放在html部分之前。
答案 1 :(得分:0)
将您的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>