Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6677341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:06:26+00:00 2026-05-26T04:06:26+00:00

I want to output the value from a dropdown menu using an echo but

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:06:27+00:00Added an answer on May 26, 2026 at 4:06 am

    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>";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to extract a value from my hidden inputbox, by using javascript, but
I want to remove . from all decimal value from my query output like
Using Sql Server I want to get max value from two table Table1 ID
I want to output the value of a double in it's full precision. However,
I want to output my own object to a STL stream but with customized
I have a value from a row in MySQL called ($)lesson_title... I want this
I want to add the value from my database to a label. The value
What I want is to use a boolean value from applicationContext.properties (Jboss configuration file)
I want to update the value from a input/textfield with a calculated value from
I want to make custom search This is the output url from the form

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.