Wrox Programmer Forums
|
BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5
This is the forum to discuss the Wrox book Beginning PHP4 by Wankyu Choi, Allan Kent, Chris Lea, Ganesh Prasad, Chris Ullman; ISBN: 9780764543647
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 19th, 2004, 08:57 AM
Registered User
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default undifined variables

chapter 13 - file register.php

the file either displays a form or registers the users submitted details. the Switch below determines whether the form has been submitted or not:

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

i am recieving the following error when i load the file:
Notice: Undefined variable: action in ...

which makes sense to me as the hidden field in the form "action" has not yet been submited.

so why does this code expect the variable "action" to be defined before it is???

 
Old April 19th, 2004, 06:19 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

That means $action didn't exist before you tried using it, add a check of the variable's existence before the switch.

if (isset($action))
{
   switch($action) {
      case "register":
         create_account();
      break;
      default:
         html_header();
         register_form();
         html_footer();
   }
}

See:
 http://www.php.net/isset
 http://www.php.net/empty
 http://www.php.net/manual/en/security.errors.php

hth,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
variables daniel.mihalcea Javascript 1 September 9th, 2008 07:06 PM
using variables webgrphx Classic ASP Basics 3 April 11th, 2007 06:46 PM
Global Variables in C# su C# 2 December 11th, 2006 06:18 PM
Passing Variables silve1999 Pro Java 1 June 15th, 2006 12:54 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.