Solved

Undefined Variable when loading page

Posted on 2003-11-27
3
939 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

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 …
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
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 look for a specific file type in a local or remote server directory using PHP.

760 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

21 Experts available now in Live!

Get 1:1 Help Now