Solved

Undefined variable on 2nd page in multi page form

Posted on 2008-06-09
4
338 Views
Last Modified: 2009-12-16
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?
0
Comment
Question by:vrmetro
  • 2
4 Comments
 
LVL 82

Assisted Solution

by:hielo
hielo earned 250 total points
ID: 21744822
>>Here is where the error_msg is set:...
but that must appear before line 15 on the SAME php file. Also, if you are using dot equal
$error_msg .= "E-mail addresses don't match";  

then $error_msg should be initialized to "". You could even try changing line 15 to:
if ( !empty($error_msg) ){
0
 
LVL 29

Expert Comment

by:fibo
ID: 21744848
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: }

0
 

Author Comment

by:vrmetro
ID: 21744926
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;
?>
0
 
LVL 82

Accepted Solution

by:
hielo earned 250 total points
ID: 21745010
Like I said before, initialize the variable
<?php
session_start();
$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";      
}
$_SESSION ['name'] = $_POST ['name'];
$_SESSION ['mobile_num'] = $_POST ['mobile_num'];
$_SESSION ['password'] = $_POST ['password'];
$_SESSION ['country'] = $_POST ['country'];
 
//Validation Ended
if ( !empty($error_msg) ){
      $_SESSION['error_prn']=$error_msg;
      header("Location: page1.php");
}
 
//function check_email($addr){
//      return preg_match(".+@.+.[\d\D]+",$addr);
//}
//$_SESSION = $_POST;
?>

Open in new window

0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question