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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T17:52:20+00:00 2026-06-03T17:52:20+00:00

Please is there a way i can make my error display dynamic for only

  • 0

Please is there a way i can make my error display dynamic for only the fields that have errors display under each textbox.

The I normally use displays only one error for all of the fields when one field is empty…

Thanks

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

    $a = mysql_real_escape_string($_POST      ['a']);

   $b = mysql_real_escape_string($_POST       ['b']);

    $c = mysql_real_escape_string($_POST      ['c']);

    $d = mysql_real_escape_string($_POST      ['d']);

    $e = mysql_real_escape_string($_POST      ['e']);


if (($a == "") ||  ($b == "") || ($c == "") ||        ($d == "") || ($e == "")) {

               echo "<div id=\"content\" >" ;
               echo "<div class=\"error\" >" ;  
               echo "empty"; 
               echo "</div>";
               echo "</div>";
            } else { 

 $query = "INSERT INTO user (a, b, c, d, e)
                   VALUES ($a, $b, $c, $d, $e)";
                   mysql_query($query);          


                  }
             }

             ?>

    Enter Texts <br/>
     <form action="<?php echo $_SERVER        ['PHP_SELF']; ?>" method="post"> 

 A:<input type="text"  name="a" ><br/>
 B:<input type="text"  name="b" ><br/>
 C:<input type="text"  name="c" ><br/>
 D:<input type="text"  name="d" ><br/>
 E:<input type="text"  name="e" ><br/>

                    <input type="submit" name           ="submit" value="Go"/> 
     </form>

thank you.

  • 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-03T17:52:22+00:00Added an answer on June 3, 2026 at 5:52 pm

    Here is an alternative way todo it, checking and building upon an error array as you go, then if the error array is empty do query.

    <?php
    //Check form was posted
    if($_SERVER['REQUEST_METHOD']=='POST'){
        //Pre build allowed array
        $allowed=array('a','b','c','d','e','submit');
        //Pre build errors array
        $errors=array('A was not set',
                      'B was not set',
                      'C was not set',
                      'D was not set',
                      'E was not set');
        //Create Blank error array    
        $error=array();
        //Loop through the POST
        foreach($_POST as $key=>$value){
            //If key is in allowed array
            if(in_array($key,$allowed)){
                //Check its at good length
                if(strlen(trim($value)) >= 1){
                    //Assign variable variable the key and value + escape
                    $$key = mysql_real_escape_string(trim($value));
                }else{
                    //Assign key/value null
                    $$key = null;
                    //Assign the error from the errors array to the output error array
                    $error[$key] = $errors[array_search($key,$allowed)];
                }
            }else{
                $error=array('Rouge POST key');
            }
        }
    
        //If all is good do query
        if(empty($error)){
            $query = "INSERT INTO user (a, b, c, d, e)
                       VALUES ($a, $b, $c, $d, $e)";
            mysql_query($query);
        }
    
    }?>
    
    Enter Texts <br/>
    <form action="" method="post"> 
    
     A:<input type="text"  name="a" ><?php echo (isset($error['a'])?$error['a']:null)?><br/>
     B:<input type="text"  name="b" ><?php echo (isset($error['b'])?$error['b']:null)?><br/>
     C:<input type="text"  name="c" ><?php echo (isset($error['c'])?$error['c']:null)?><br/>
     D:<input type="text"  name="d" ><?php echo (isset($error['d'])?$error['d']:null)?><br/>
     E:<input type="text"  name="e" ><?php echo (isset($error['e'])?$error['e']:null)?><br/>
     <input type="submit" name="submit" value="Go"/> 
    </form>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If there is more than one way, please list them. I only know of
Is there a coding standard for HTML? Please suggest links that have the coding
I have the following code that won't compile and although there is a way
Can anyone please tell me is there any special requirement to use either EXTERN
Can anyone please advise me if there will be any problems changing the wordpress
**EDIT: There are several options below that would work. Please vote/comment according to your
I have a homework that I just can't figure out how to do. I'm
Please let me know why there is lot of white space below the page
Could you please tell me if there is any equivalent of Access' DISTINCTROW for
Is there a parser/library for css stylus available for php? If not please suggest

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.