Solved

Undefined variable on 2nd page in multi page form

Posted on 2008-06-09
4
335 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
Comment Utility
>>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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now