html - PHP Display post variables -


i'm looking bit of , bit of explanation here.

i have created html form several input fields , basic php validation when posting inputs. validation checks see if field has data , if not, prompts user enter data in field displaying error. hope post these inputs, check them against database, , if aren't there, add them database. but, not issue @ hand.

currently, objective take of inputs in field want post , display them in field below error display area. had hoped echo data reason, not of entered data appears.

of 5 entry fields in code below, 4 basic input fields , 1 text area. if enter basic input fields, last input echo in display area. if enter field 1 , leave rest blank, field 1 display. also, if enter text area, display. finally, php validation not appear work textarea type input (labeled 'note') , not return error if 'note' input left blank.can explain: (1) how fix 5 inputs display in display div?; (2) why happen?; (3) why no error returned if text area (labeled 'note') left blank?

thank you.

<!doctype html> <html lang="en"> <head>     <meta charset="utf-8">     <title>document</title> </head> <body>  <?php //form validation general entry form      // define variables , set empty values     $clienterr = $mattererr = $dateerr = $timeerr = $noteerr= "";     $client = $matter = $date = $time = $note = "";       //on post, check see if variable empty. if not empty     //parse , assign value variable name      if ($_server["request_method"] == "post") {         $complete = true;         $postarray = [];           if (empty($_post["client"])) {             $clienterr = "*a client name required. ";             $complete = false;         }else {               $client = test_input($_post["client"]);             //$postarray[] =  $client;         }           if (empty($_post["matter"])) {             $mattererr = "*a matter name required. ";             $complete = false;         }else {             $client = test_input($_post["matter"]);         }           if (empty($_post["date"])) {             $dateerr = "*a date required. ";             $complete = false;         }else {             $client = test_input($_post["date"]);         }           if (empty($_post["time"])) {             $timeerr = "*a time entry required. ";             $complete = false;         }else {             $client = test_input($_post["time"]);         }          if (empty($_post["note"])) {             $noteerr = "*a note required. ";             $complete = false;         } else {             $note = test_input($_post["note"]);         }      }       function test_input($data) {       $data = trim($data);       $data = stripslashes($data);       $data = htmlspecialchars($data);       return $data;     } ?>   <form method="post" action="<?php echo htmlspecialchars($_server["php_self"]);?>" >      <label for="client">client:</label>     <input type="text" placeholder = "enter client name" name="client"> *       <label for="matter">matter:</label>     <input type="text" placeholder = "enter matter name" name="matter"> *      <label for="date">date:</label>     <input type="text" placeholder = "enter date" name="date"> *      <label for="time">time:</label>      <input type="text" placeholder ="time nearest tenth hour" name="time"> *      <label for="note">note:</label>     <textarea name="note" placeholder ="enter notes" rows="4" cols="40"></textarea>   <input type="submit" name="submit" value="submit" class="submitbutton">   </form>     <div class="errordiv">     <?php          echo $clienterr;         echo $mattererr;          echo $dateerr;         echo $timeerr;      ?>        </div>  <div class ="displaydiv">     <?php              echo "<h2>your input:</h2>";             echo $client;             echo "<br>";             echo $matter;             echo "<br>";             echo $date;             echo "<br>";             echo $time;             echo "<br>";             echo $note;        ?> </div>   </body> </html> 

 <!doctype html>     <html lang="en">     <head>         <meta charset="utf-8">         <title>document</title>     </head>     <body>      <?php     //form validation general entry form          // define variables , set empty values         $clienterr = $mattererr = $dateerr = $timeerr = $noteerr= "";         $client = $matter = $date = $time = $note = "";           //on post, check see if variable empty. if not empty         //parse , assign value variable name          if ($_server["request_method"] == "post") {             $complete = true;             $postarray = [];               if (empty($_post["client"])) {                 $clienterr = "*a client name required. ";                 $complete = false;             }else {                   $client = test_input($_post["client"]);                 //$postarray[] =  $client;             }               if (empty($_post["matter"])) {                 $mattererr = "*a matter name required. ";                 $complete = false;             }else {                 $matter = test_input($_post["matter"]);  //remove $client , assign value $matter             }               if (empty($_post["date"])) {                 $dateerr = "*a date required. ";                 $complete = false;             }else {                 $date = test_input($_post["date"]); //remove $client , assign value $date             }               if (empty($_post["time"])) {                 $timeerr = "*a time entry required. ";                 $complete = false;             }else {                 $time = test_input($_post["time"]); //remove $client , assign value $time             }              if (empty($_post["note"])) {                 $noteerr = "*a note required. ";                 $complete = false;             } else {                 $note = test_input($_post["note"]);             }          }           function test_input($data) {           $data = trim($data);           $data = stripslashes($data);           $data = htmlspecialchars($data);           return $data;         }     ?>       <form method="post" action="<?php echo htmlspecialchars($_server["php_self"]);?>" >          <label for="client">client:</label>         <input type="text" placeholder = "enter client name" name="client"> *           <label for="matter">matter:</label>         <input type="text" placeholder = "enter matter name" name="matter"> *          <label for="date">date:</label>         <input type="text" placeholder = "enter date" name="date"> *          <label for="time">time:</label>          <input type="text" placeholder ="time nearest tenth hour" name="time"> *          <label for="note">note:</label>         <textarea name="note" placeholder ="enter notes" rows="4" cols="40"></textarea>       <input type="submit" name="submit" value="submit" class="submitbutton">       </form>         <div class="errordiv">         <?php              echo $clienterr;             echo $mattererr;              echo $dateerr;             echo $timeerr;              echo $noteerr;  // echo noteerror here.........         ?>            </div>      <div class ="displaydiv">         <?php                  echo "<h2>your input:</h2>";                 echo $client;                 echo "<br>";                 echo $matter;                 echo "<br>";                 echo $date;                 echo "<br>";                 echo $time;                 echo "<br>";                 echo $note;            ?>     </div>       </body>     </html> 

here assign values single variable $client , echo different variable assign value particular variable $matter, $date, $time. , forget echo $noteerror in error messsages.


Comments