Link to home
Start Free TrialLog in
Avatar of vrmetro
vrmetroFlag for United States of America

asked on

Undefined variable on 2nd page in multi page form

Notice: Undefined variable: error_msg in D:\data\Inetpub\wwwweb_verynew\mobile_form\plan.php on line 15

15: if ($error_msg){
16: $_SESSION['error_prn']=$error_msg;
17: header("Location: page1.php");
18: }

Here is where the error_msg is set:
if ($_POST['email'] === $_POST['vemail']){ //AND check_email($_POST['email'])){
$_SESSION['email']=$_POST['email'];
} else {
$error_msg .= "E-mail addresses don't match";      
}

Any thoughts?
SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I would think that when the page is first launched $error_msg is not defined, nor set.
You might try something like:

$error_msg='';
....
if ($_POST['email'] === $_POST['vemail']){ //AND check_email($_POST['email'])){
$_SESSION['email']=$_POST['email'];
} else {
$error_msg .= "E-mail addresses don't match";      
};
...

15: if ($error_msg <> '' ){
16: $_SESSION['error_prn']=$error_msg;
17: header("Location: page1.php");
18: }

Avatar of vrmetro

ASKER

I'm sorry, this is the 2nd page, in a multi-page form, and the error msg is set after validation, see below entire code.

<?php
session_start();

if ($_POST['email'] === $_POST['vemail']){ //AND check_email($_POST['email'])){
      $_SESSION['email']=$_POST['email'];
} else {
      $error_msg .= "E-mail addresses don't match";      
}
$_SESSION ['name'] = $_POST ['name'];
$_SESSION ['mobile_num'] = $_POST ['mobile_num'];
$_SESSION ['password'] = $_POST ['password'];
$_SESSION ['country'] = $_POST ['country'];

//Validation Ended
if ($error_msg){
      $_SESSION['error_prn']=$error_msg;
      header("Location: page1.php");
}

//function check_email($addr){
//      return preg_match(".+@.+.[\d\D]+",$addr);
//}
//$_SESSION = $_POST;
?>
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial