Solved

Undefined Variable when loading page

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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.

679 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