Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Undefined variable on 2nd page in multi page form

Posted on 2008-06-09
4
Medium Priority
?
343 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 1000 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 1000 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

609 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