Solved

Undefined Variable when loading page

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Undefined Index in HTML Form? 2 32
What is the best PDF generator to use? 1 30
PHP get array item with custom id 4 24
php function to remove a file 26 11
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 …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

867 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