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 8974215
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:37:50+00:00 2026-06-15T18:37:50+00:00

I want to display a list of all the errors below but instead it

  • 0

I want to display a list of all the errors below but instead it is only displaying one error at a time, does anyone know why my code is not displaying a list of errors? Below is the code display the array to store the errors, the code for stating what happens if there is are no errors, and the code stating what happens if there are errors.

    <?php 

  $getcourseid = (isset($_POST['courseid'])) ? $_POST['courseid'] : '';
  $getcoursename = (isset($_POST['coursename'])) ? $_POST['coursename'] : '';
  $getduration = (isset($_POST['duration'])) ? $_POST['duration'] : '';

        $errors = array();


                  if (!$getcourseid){
                      $errors[] = "You must enter in Course's ID";
              }else if (!$getcoursename){
                  $errors[] = "You must enter in Course's Name";
              }else if (!$getduration){
                      $errors[] = "You must select Course's Duration";
                  }   

          if(!$errors) {

         $insertsql = "
        INSERT INTO Course
            (CourseNo, CourseName, Duration)
          VALUES
            (?, ?, ?)
        ";
        if (!$insert = $mysqli->prepare($insertsql)) {
          // Handle errors with prepare operation here
        }                                           

        $insert->bind_param("sss", $getcourseid, $getcoursename, $getduration);

        $insert->execute();

        if ($insert->errno) {
          // Handle query error here
        }

        $insert->close();

         // don't use $mysqli->prepare here
    $query = "SELECT CourseNo FROM Course WHERE CourseNo = ?";
    // prepare query
    $stmt=$mysqli->prepare($query);
    // You only need to call bind_param once
    $stmt->bind_param("s",$getcourseid);
    // execute query
    $stmt->execute(); 
    // get result and assign variables (prefix with db)
    $stmt->bind_result($dbCourseId);
    //get number of rows
    $stmt->store_result();
    $numrows = $stmt->num_rows();  

              }  



            if(empty($errors)) {
                if ($numrows == 1){
               $errormsg = "<span style='color: green'>Course " . $getcourseid .  " - "  . $getcoursename . " has been Created</span>";
               $getcourseid = "";
               $getcoursename = "";
               $getduration = "";
            }else{
                $errormsg = "An error has occured, Course has not been Created";
            }
            } else {
                if (count($errors) > 0)
                {
                    foreach ($errors AS $Errors)
                    {
                        $errormsg = "{$Errors} <br>"; 
                    }
                }
            }     
        ?>

**ADDITIONAL QUESTION:**



    $form = "
    <form action='" . htmlentities($_SERVER["PHP_SELF"]) . "' method='post'>
      <table>
      <tr>
      <td></td>
      <td id='errormsg'>$errormsg</td>
      </tr>
      <tr>
      <td>Course ID:</td>
      <td><input type='text' name='courseid' value='$getcourseid' /></td>
      </tr>
      <tr>
      <td>Course Name:</td>
      <td><input type='text' id='nameofcourse' name='coursename' value='$getcoursename' /></td>
      </tr>
      <tr>
      <td>Duration (Years):</td>
      <td>{$durationHTML}</td>
      </tr>
      <tr>
      <td></td>
      <td><input type='submit' value='Create Course' name='createbtn' /></td>
      </tr>
      </table>
      </form>";

      echo $form;

The above form goes below the php code at the top of this question. Now what is happening is that the list of validation errors are all being displayed at the top of the form. But what I really want is each validation error to go below the form feature it is referring to.

E.g If I have not filled in the Course Id text input, then I want the validation error "You must enter in Course's ID" to be displayed below the Course Id text input.

If I have not filled in the Course Name text input, then I want the validation error "You must enter in Course's Name" to be displayed below the Course Name text input.

etc. What needs to be changed in code in order to do this?

  • 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-15T18:37:52+00:00Added an answer on June 15, 2026 at 6:37 pm

    try

          if (!$getcourseid){
              $errors[] = "You must enter in Course's ID";
           } 
         if (!$getcoursename){
             $errors[] = "You must enter in Course's Name";
          }
          if (!$getduration){
              $errors[] = "You must select Course's Duration";
          } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to display a list of all the users in my site but
I want my iPhone App to display a list of ALL Bluetooth Devices nearby
I want to display a list of complex, but fixed-size multiline elements, assuming that
I want to make some kind of list of errors in C#, but I'm
Ok, So I want to display some attributes, but only if they have a
Rails beginner here. I want to display a list of all products belonging to
I want to display a list of all the databases on my server, when
I want to display list of people in the iPhone's address book with atleast
i want to display a list of emails to whom i send an email
I want to display a list of related products in my eshop. The problem

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.