Solved

Undefined Variable when loading page

Posted on 2003-11-27
3
951 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
[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
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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

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…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
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…

759 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