user1247412
user1247412

Reputation: 647

Redirecting error message in php

I have a login.php (input form) and loginvalidation.php(server side validations). I want to display an error message on login.php when input is invalid. I am not able to redirect user to login.php and display error message on it. On Login.php the error message field is <label id="lblErrorMessage" style="color: red;"><?=$errorString?></label>.

Upvotes: 1

Views: 633

Answers (2)

Teson
Teson

Reputation: 6736

I presume you have a form in login.php with

 <form method="post" action="loginvalidation.php">

In loginvalidation.php add

 if ($badLogin) header('location:login.php?err=badLogin');

And catch the err in login.php

$err = $_GET['err'];

I'd recommend to put the validation and form in the same php-page.

<?php
if($_SERVER['REQUEST_METHOD'] == 'POST') {
  //validate and if ok maby redirect (application dependent)
  //if no redirect - we still need to login
  $err = 'no good';
 ?>
 <html>the login form...

regards, /t

Upvotes: 3

cjtech
cjtech

Reputation: 459

What I do for login forms -

  1. I set the action to (in your case) login.php,
  2. do error checking
  3. a. display the errors if there are any - or -
  4. b. If there aren't any errors I then redirect to the main page.

Upvotes: 0

Related Questions