编辑:我现在解决了这个问题,但如果有人能告诉我是否有其他方式或为什么之前没有工作请告诉我!
我有一个页面正在接收来自上一页的ID,根据该ID可以查看某人的课程表。我在类计划页面上添加了一个链接,将它们带回到类页面的注册表中,但每次没有id时我都会收到错误。我将id存储在隐藏字段中,但由于某种原因,它不会与链接一起传递。不确定为什么没有传递该值,因为它与其他页面的代码相同。谢谢你的帮助!
以下是注册页面的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Course Listings</title>
<link rel="stylesheet" href="php_styles.css" type="text/css" />
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Aqua Don's Scuba School</h1>
<h2>Class Registration Form</h2>
<?php
$DBConnect = @mysqli_connect("localhost", "students", "password")
Or die("<p>Unable to connect to the database server.</p>"
. "<p>Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . "</p>";
$DBName = "scuba_school";
@mysqli_select_db($DBConnect, $DBName)
Or die("<p>Unable to select the database.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
$DiverID = $_GET['diverID'];
if (empty($DiverID))
exit("<p>You must enter a diver ID! Click your browser's Back button to return to the previous page.</p>");
$TableName = "divers";
$SQLstring = "SELECT * FROM $TableName WHERE diverID='$DiverID'";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
if (mysqli_num_rows($QueryResult) == 0)
die("<p>You must enter a valid diver ID! Click your browser's Back button to return to the Registration form.</p.");
mysqli_close($DBConnect);
?>
<form method="get" action="ReviewSchedule.php">
<p><strong>Student ID: <?= $DiverID ?></strong>
<input type="submit" value=" Review Current Schedule " /><input type="hidden" name="diverID" value="<?= $DiverID ?>" /></p>
</form>
<form method="get" action="RegisterDiver.php">
<p><strong>Select the class you would like to take:</strong><br />
<input type="radio" name="class" value="Beginning Open Water" checked="checked" />Beginning Open Water<br />
<input type="radio" name="class" value="Advanced Open Water" />Advanced Open Water<br />
<input type="radio" name="class" value="Rescue Diving" />Rescue Diving<br />
<input type="radio" name="class" value="Divemaster Certification" />Divemaster Certification<br />
<input type="radio" name="class" value="Instructor Certification" />Instructor Certification</p>
<p><strong>Available Days and Times:</strong><br />
<select name="days">
<option selected="selected" value="Mondays and Wednesdays">Mondays and Wednesdays</option>
<option value="Tuesdays and Thursdays">Tuesdays and
Thursdays</option>
<option value="Wednesdays and Fridays">Wednesdays and
Fridays</option>
</select>
<select name="time">
<option selected="selected" value="9 a.m. - 11 a.m.">9 a.m. - 11 a.m.</option>
<option value="1 p.m. - 3 p.m.">1 p.m. - 3 p.m.</option>
<option value="6 p.m. - 8 p.m.">6 p.m. - 8 p.m.</option>
</select><input type="hidden" name="diverID" value="<?= $DiverID ?>" /></p>
<p><input type="submit" value=" Register " action="RegisterDiver.php"/>
<input type="reset" /></p>
</form>
</body>
<footer>
<div align="center">
<a href="Registration.html">Return to Registration</a>
<br/>
<a href="../Menu.html">Return to Menu</a>
</div>
</footer>
</html>
以下是审核时间表页面的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Review Schedule</title>
<link rel="stylesheet" href="php_styles.css" type="text/css" />
<meta http-equiv="content-type"
content="text/html; charset=iso-8859-1" />
</head>
<body>
<h1>Aqua Don's Scuba School</h1>
<h2>This is your current schedule:</h2>
<?php
$DiverID = $_GET['diverID'];
if (empty($DiverID))
exit("<p>You must enter a diver ID! Click your browser's Back button to return to the previous page.</p>");
$DBConnect = @mysqli_connect("localhost", "students","password")
Or die("<p>Unable to connect to the database server.</p>"
. "<p>Error code " . mysqli_connect_errno()
. ": " . mysqli_connect_error()) . "</p>";
$DBName = "scuba_school";
@mysqli_select_db($DBConnect, $DBName)
Or die("<p>Unable to select the database.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
$TableName = "registration";
$SQLstring = "SELECT * FROM $TableName WHERE diverID='$DiverID'";
$QueryResult = @mysqli_query($DBConnect, $SQLstring)
Or die("<p>Unable to execute the query.</p>"
. "<p>Error code " . mysqli_errno($DBConnect)
. ": " . mysqli_error($DBConnect)) . "</p>";
if (mysqli_num_rows($QueryResult) == 0)
die("<p>You have not registered for any classes! Click your browser's Back button to return to the previous page.</p>");
echo "<table width='100%' border='1'>";
echo "<tr><th>Class</th><th>Days</th>
<th>Time</th></tr>";
$Row = mysqli_fetch_assoc($QueryResult);
do {
echo "<tr><td>{$Row['class']}</td>";
echo "<td>{$Row['days']}</td>";
echo "<td>{$Row['time']}</td></tr>";
$Row = mysqli_fetch_assoc($QueryResult);
} while ($Row);
?>
<form method="get" action="CourseListings.php">
<input type="hidden" name="diverID" value="<?= $DiverID ?>" />
<center>
<h3><a href="CourseListings.php">Return to View Course Listings</a></h3>
<h3><a href="Registration.html">Go back to Registration</a></h3>
<h3><a href="../Menu.html">Return to Menu</a></h3>
</center>
</form>
<?php
mysqli_free_result($QueryResult);
mysqli_close($DBConnect);
?>
</body>
<footer>
<div align="center">
© Copyright Ryan Strouse ©
</div>
</footer>
</html>
我明白了!我需要:
<h3><a href="CourseListings.php?diverID=<?php echo $DiverID;?>">Return to View Course Listings</a></h3>
而不是普通链接。除非有人想出更好的东西?我觉得它应该接受一切
答案 0 :(得分:0)
使用POST代替GET。
我的个人经验法则:表格的POST,通过URL传递的变量的GET。