Solved

Undefined variable on 2nd page in multi page form

Posted on 2008-06-09
4
340 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Change Wording in Wordpress Plugin 4 33
How do I Check for duplicate entries in mysql 15 47
php hashing methods 3 45
Conditional Array Element 7 23
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

738 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