根据从下拉菜单中选择的值,不输出正确的回波

发布于 2024-12-10 01:47:51 字数 4633 浏览 0 评论 0原文

我想使用回显从下拉菜单中输出值,但即使下拉菜单工作正常,回显也不会输出从下拉菜单中选择的正确值。 echo 仅输出会话 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" /></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="u0867587";
$password="31may90";
$database="mobile_app";

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

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

$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);

switch ($orderfield) {
    case 'ordersessionid': $orderfield = 'gr.SessionId';
    break;
    case 'ordermoduleid': $orderfield = 'm.ModuleId'; 
    break;
    case 'orderteacherid': $orderfield = 's.TeacherId';
    break;
    case 'orderstudentid': $orderfield = 'gr.StudentId'; 
    break;
    case 'ordergrade': $orderfield = 'gr.Grade';
    break;
}

$result = mysql_query("SELECT * FROM Module m INNER JOIN Session s ON m.ModuleId = s.ModuleId JOIN Grade_Report gr ON s.SessionId = gr.SessionId JOIN Student st ON gr.StudentId = st.StudentId WHERE ('$sessionid' = '' OR gr.SessionId = '$sessionid') AND ('$moduleid' = '' OR m.ModuleId = '$moduleid') AND ('$teacherid' = '' OR s.TeacherId = '$teacherid') AND ('$studentid' = '' OR gr.StudentId = '$studentid') AND ('$grade' = '' OR gr.Grade = '$grade') ORDER BY $orderfield ASC");

$num=mysql_numrows($result);

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

echo "<p>Your Search: <strong>Session ID:</strong> "; if (empty($sessionid))echo "'All Sessions'"; else echo "'$sessionid'";echo ", <strong>Module ID:</strong> "; if (empty($moduleid))echo "'All Modules'"; else echo "'$moduleid'";echo ", <strong>Teacher Username:</strong> "; if (empty($teacherid))echo "'All Teachers'"; else echo "'$teacherid'";echo ", <strong>Student Username:</strong> "; if (empty($studentid))echo "'All Students'"; else echo "'$studentid'";echo ", <strong>Grade:</strong> "; if (empty($grade))echo "'All Grades'"; else echo "'$grade'"; echo ", <strong>Order Results By:</strong>";if ($orderfield = 'gr.SessionId') echo " 'Session ID'"; else if ($orderfield = 'ordermoduleid') echo " 'Module Number' "; else if ($orderfield = 's.TeacherId') echo " 'Teacher Username' "; else if ($orderfield = 'gr.StudentId') echo " 'Student Username' "; else if ($orderfield = 'gr.Grade') echo " 'Grade' ";"</p>";

mysql_close();


 ?>

</body>
</html>

任何帮助将不胜感激。

I want to output the value from a dropdown menu using an echo but even though the dropdown menu works perfectly, the echo is not outputting the right value chosen from the drop down menu. The echo only output Session ID and that is it. Can you help me with this please. The echo is at the bottom of the code.

Below is my 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" /></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="u0867587";
$password="31may90";
$database="mobile_app";

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

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

$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);

switch ($orderfield) {
    case 'ordersessionid': $orderfield = 'gr.SessionId';
    break;
    case 'ordermoduleid': $orderfield = 'm.ModuleId'; 
    break;
    case 'orderteacherid': $orderfield = 's.TeacherId';
    break;
    case 'orderstudentid': $orderfield = 'gr.StudentId'; 
    break;
    case 'ordergrade': $orderfield = 'gr.Grade';
    break;
}

$result = mysql_query("SELECT * FROM Module m INNER JOIN Session s ON m.ModuleId = s.ModuleId JOIN Grade_Report gr ON s.SessionId = gr.SessionId JOIN Student st ON gr.StudentId = st.StudentId WHERE ('$sessionid' = '' OR gr.SessionId = '$sessionid') AND ('$moduleid' = '' OR m.ModuleId = '$moduleid') AND ('$teacherid' = '' OR s.TeacherId = '$teacherid') AND ('$studentid' = '' OR gr.StudentId = '$studentid') AND ('$grade' = '' OR gr.Grade = '$grade') ORDER BY $orderfield ASC");

$num=mysql_numrows($result);

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

echo "<p>Your Search: <strong>Session ID:</strong> "; if (empty($sessionid))echo "'All Sessions'"; else echo "'$sessionid'";echo ", <strong>Module ID:</strong> "; if (empty($moduleid))echo "'All Modules'"; else echo "'$moduleid'";echo ", <strong>Teacher Username:</strong> "; if (empty($teacherid))echo "'All Teachers'"; else echo "'$teacherid'";echo ", <strong>Student Username:</strong> "; if (empty($studentid))echo "'All Students'"; else echo "'$studentid'";echo ", <strong>Grade:</strong> "; if (empty($grade))echo "'All Grades'"; else echo "'$grade'"; echo ", <strong>Order Results By:</strong>";if ($orderfield = 'gr.SessionId') echo " 'Session ID'"; else if ($orderfield = 'ordermoduleid') echo " 'Module Number' "; else if ($orderfield = 's.TeacherId') echo " 'Teacher Username' "; else if ($orderfield = 'gr.StudentId') echo " 'Student Username' "; else if ($orderfield = 'gr.Grade') echo " 'Grade' ";"</p>";

mysql_close();


 ?>

</body>
</html>

Any help will be much appreciated.

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

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

发布评论

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

评论(2

风流物 2024-12-17 01:47:51

在每个实例中,您都会覆盖 $orderfield,因为您使用的是 = 而不是 ==。您不是测试 $odrerfield 的值,而是分配 $orderfield 的值。

if ($orderfield = 'gr.SessionId')

// Should be
if ($orderfield == 'gr.SessionId')

对随后的所有实例进行相同的更改。强烈建议将长回声线分成多条线。

echo "<p>Your Search: <strong>Session ID:</strong> "; 
if (empty($sessionid))echo "'All Sessions'"; 
else echo "'$sessionid'";
echo ", <strong>Module ID:</strong> "; 
if (empty($moduleid))echo "'All Modules'"; 
else echo "'$moduleid'";
echo ", <strong>Teacher Username:</strong> "; 
if (empty($teacherid))echo "'All Teachers'"; 
else echo "'$teacherid'";
echo ", <strong>Student Username:</strong> "; 
if (empty($studentid))echo "'All Students'"; 
else echo "'$studentid'";
echo ", <strong>Grade:</strong> "; 
if (empty($grade))echo "'All Grades'"; 
else echo "'$grade'"; 
echo ", <strong>Order Results By:</strong>";
if ($orderfield == 'gr.SessionId') echo " 'Session ID'"; 
else if ($orderfield == 'ordermoduleid') echo " 'Module Number' "; 
else if ($orderfield == 's.TeacherId') echo " 'Teacher Username' "; 
else if ($orderfield == 'gr.StudentId') echo " 'Student Username' "; 
else if ($orderfield == 'gr.Grade') echo " 'Grade' ";"</p>";

In every instance, you overwrite $orderfield because you are using = instead of ==. Rather than testing the value of $odrerfield, you are assigning the value of $orderfield.

if ($orderfield = 'gr.SessionId')

// Should be
if ($orderfield == 'gr.SessionId')

Make the same change for all the instances that follow. It is highly advisable to break up that long echo line into multiple lines.

echo "<p>Your Search: <strong>Session ID:</strong> "; 
if (empty($sessionid))echo "'All Sessions'"; 
else echo "'$sessionid'";
echo ", <strong>Module ID:</strong> "; 
if (empty($moduleid))echo "'All Modules'"; 
else echo "'$moduleid'";
echo ", <strong>Teacher Username:</strong> "; 
if (empty($teacherid))echo "'All Teachers'"; 
else echo "'$teacherid'";
echo ", <strong>Student Username:</strong> "; 
if (empty($studentid))echo "'All Students'"; 
else echo "'$studentid'";
echo ", <strong>Grade:</strong> "; 
if (empty($grade))echo "'All Grades'"; 
else echo "'$grade'"; 
echo ", <strong>Order Results By:</strong>";
if ($orderfield == 'gr.SessionId') echo " 'Session ID'"; 
else if ($orderfield == 'ordermoduleid') echo " 'Module Number' "; 
else if ($orderfield == 's.TeacherId') echo " 'Teacher Username' "; 
else if ($orderfield == 'gr.StudentId') echo " 'Student Username' "; 
else if ($orderfield == 'gr.Grade') echo " 'Grade' ";"</p>";
无言温柔 2024-12-17 01:47:51
cho "<p>Your Search: <strong>Session ID:</strong> "; if (empty($sessionid))echo "'All Sessions'"; else echo "'$sessionid'";echo ", <strong>Module ID:</strong> "; if (empty($moduleid))echo "'All Modules'"; else echo "'$moduleid'";echo ", <strong>Teacher Username:</strong> "; if (empty($teacherid))echo "'All Teachers'"; else echo "'$teacherid'";echo ", <strong>Student Username:</strong> "; if (empty($studentid))echo "'All Students'"; else echo "'$studentid'";echo ", <strong>Grade:</strong> "; if (empty($grade))echo "'All Grades'"; else echo "'$grade'"; echo ", <strong>Order Results By:</strong>";if ($orderfield = 'gr.SessionId') echo " 'Session ID'"; else if ($orderfield = 'ordermoduleid') echo " 'Module Number' "; else if ($orderfield = 's.TeacherId') echo " 'Teacher Username' "; else if ($orderfield = 'gr.StudentId') echo " 'Student Username' "; else if ($orderfield = 'gr.Grade') echo " 'Grade' ";"</p>";

您在上面的 if 条件上使用了错误的比较运算符,例如 - if($orderfield = 'ordermoduleid'),这些将类似于 - if($orderfield == 'ordermoduleid')

cho "<p>Your Search: <strong>Session ID:</strong> "; if (empty($sessionid))echo "'All Sessions'"; else echo "'$sessionid'";echo ", <strong>Module ID:</strong> "; if (empty($moduleid))echo "'All Modules'"; else echo "'$moduleid'";echo ", <strong>Teacher Username:</strong> "; if (empty($teacherid))echo "'All Teachers'"; else echo "'$teacherid'";echo ", <strong>Student Username:</strong> "; if (empty($studentid))echo "'All Students'"; else echo "'$studentid'";echo ", <strong>Grade:</strong> "; if (empty($grade))echo "'All Grades'"; else echo "'$grade'"; echo ", <strong>Order Results By:</strong>";if ($orderfield = 'gr.SessionId') echo " 'Session ID'"; else if ($orderfield = 'ordermoduleid') echo " 'Module Number' "; else if ($orderfield = 's.TeacherId') echo " 'Teacher Username' "; else if ($orderfield = 'gr.StudentId') echo " 'Student Username' "; else if ($orderfield = 'gr.Grade') echo " 'Grade' ";"</p>";

You have used wrong compare operator on the if condition above, like - if($orderfield = 'ordermoduleid'), these will be like - if($orderfield == 'ordermoduleid')

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