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

  • SEARCH
  • Home
  • 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 8927631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:15:45+00:00 2026-06-15T08:15:45+00:00

I have a code below where it displays students details in a drop down

  • 0

I have a code below where it displays students details in a drop down menu, and then it does a php validation to see if a student is selected from the drop down menu or not:

$sql = "SELECT StudentUsername, StudentForename, StudentSurname FROM Student ORDER BY StudentUsername"; 

$sqlstmt = $mysqli->prepare($sql);

$sqlstmt->execute(); 

$sqlstmt->bind_result($dbStudentUsername, $dbStudentForename, $dbStudentSurname);

$students = array(); // easier if you don't use generic names for data 

$studentHTML = "";  
$studentHTML .= '<select name="students" id="studentsDrop">'.PHP_EOL; 
$studentHTML .= '<option value="">Please Select</option>'.PHP_EOL;  

$outputstudent = "";

while($sqlstmt->fetch()) 
{
    $student = $dbStudentUsername;
    $firstname = $dbStudentForename;
    $surname = $dbStudentSurname; 

    $studentHTML .= "<option value='" . $student . "'>" . $student . " - " . $firstname . " " . $surname . "</option>" . PHP_EOL;  
} 

$studentHTML .= '</select>'; 

$errormsg = (isset($errormsg)) ? $errormsg : '';

if(isset($_POST['resetpass'])) {
    //get the form data
    $studentdrop = (isset($_POST['students'])) ? $_POST['students'] : '';

    if($studentdrop = "") {
        $errormsg = "Student is Selected";
    }
    else{
        $errormsg = "You must Select a Student";
    }

}

The problem I have though is that even though I have selected a student from the drop down menu, it still displays a message stating that “You Must select a Student”.

What is suppose to happen is that if the user has not selected a student or in other words when they have submitted the form and the drop down menu is still on the “Please Select” option, then it displays the message stating that user must select a student, else if the user does select a student from the drop down menu then display the message that a student has been selected.

  • 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-06-15T08:15:46+00:00Added an answer on June 15, 2026 at 8:15 am

    You should use if($studentdrop == ""){ for equally or if($studentdrop != ""){ for not equally. Be aware on comparison operator.

    If you use if($studentdrop = ""){, it means that you assign empty string to variable $studentdrop.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code below in the module.php script where it displays options in
I'm a EE newbie. I have the code below. the poll weblog displays at
I have code below where the user types in a Course, then it will
I have the following unorderered list code which displays the list below: <ul> <li
I have the code below that displays information about a computer. I am having
I have a code below where it displays a text input in one column,
In the code below I have two types of validation. I use a javascript
I have a code below where it displays a text input in one column,
I have this code below where the problem is that it displays the <span>
I have the code below for a category in WordPress. It displays the name

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.