Printing validation message on the same page in PHP -


hi have function in handling upload errors.

function error($error, $location, $seconds = 5) {     header("refresh: $seconds; url=\"$location\"");     echo 'error :' . $error . ' please correct before proceeding.';     exit; }  

since echo's message, know message shows not in same page , need hit browser return original content page.

what wanted validation messages shown on same page, tried changing code following.

function error($error) {     $errmsg = 'error :' . $error . ' please correct before proceeding.';  }  

and later in form in table have following call massage.

<td><?php if(!empty($errmsg)) echo $errmsg; ?></td> 

however method doesn't seems giving me solution need, print validation message on same page.

can help?

thanks.

you use ajax call error function , output message on page.

or set $_post, $_get, or $_session variable pass error message onto next page.

session example:

function error($error) {     $_session['errmsg'] = 'error :' . $error . ' please correct before proceeding.'; }  

and later...

<td> <?php if (!empty($_session['errmsg'])) {  echo $_session['errmsg'];  }?> </td> 

if form posts same page it's on, try this:

function uploadvalidation() {     $errorreason = '';     // validation here     // if goes wrong $errorreason = 'reason error'      if (!empty($errorreason)) {         return 'error :' . $errorreason . ' please correct before proceeding.';     } else {         // success stuff         // maybe return message or redirect somewhere else?         return 'you upload real good!';     } }  $validationmessage = uploadvalidation(); ?>  , later in form in table have following call massage.  <td><?= $validationmessage ?></td> 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -