Solved

Undefined Variable when loading page

Posted on 2003-11-27
3
947 Views
Last Modified: 2006-11-17
Hi everyone,

Created a php page.  First couple of lines have code that open and connect to a mysql database. The next lines of code are functions. After I finished with the function I have a switch statement as follows:

<?php
switch($action) {
   case "register":
      create_account();
   break;
   default:
      html_header();
      register_form();
      html_footer();
   break;
}
?>

This is a user registration page. the variable $action is a hidden text assigned within a form and is assigned the value of "register". If the user first opens the page the $action variable has no value thus it will create a registration form (register_form()), but if the user submits the form the variable should have the value of "register". when I load the page I get undefined Variable.

What am I doing wrong?

Thanks
Chris
0
Comment
Question by:clekkas
3 Comments
 
LVL 24

Expert Comment

by:shivsa
ID: 9833848
check the register_form()

u have to define variable like this, eg :ssn is variable.

$ssn = $_POST['ssn'];
0
 
LVL 5

Accepted Solution

by:
arjanh earned 50 total points
ID: 9833854
use the isset() function to test if $action is set:

if (isset( $action )) {
      if ( $action = "register" ) {
           create_account();
      } else {
           # probably not possible...
      }
} else {
      html_header();
      register_form();
      html_footer();
}
0
 

Author Comment

by:clekkas
ID: 9833877
Thank you very much to everyone
That isset() worked perfectly.

Chris
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

828 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