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 November 2nd, 2003, 04:05 PM
Registered User
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default ch 13 enum_options.php not working

Ok, so I started in the middle of the book. Actually I have been going through the db access portion of the book and was having trouble with the register.php not working.

Here is the error I keep getting:

Warning: array_push(): First argument should be an array in /home/thurmma/public_html/staging/enum_options.php on line 16
ENUM options with the default value:

Warning: Invalid argument supplied for foreach() in /home/thurmma/public_html/staging/enum_options.php on line 19


Warning: array_pop(): The argument should be an array in /home/thurmma/public_html/staging/enum_options.php on line 23
ENUM options without the default value:

Warning: Invalid argument supplied for foreach() in /home/thurmma/public_html/staging/enum_options.php on line 26

I am not very knowledgable in arrays at all. Here is the code from the page:

<?php
//enum_options.php
include "./common_db.inc";
$link_id = db_connect();
mysql_select_db("mojoweb_sampledb");

$query = "SHOW COLUMNS FROM user LIKE 'usercountry'";
$result = mysql_query($query);
$query_data = mysql_fetch_array($result);

if(eregi("('.*')", $query_data["Type"], $match)) {
   $enum_str = ereg_replace("'", "", $match[1]);
   $enum_options = explode(',', $enum_str);
}

array_push($enum_options, $query_data["Default"]);

echo "ENUM options with the default value:<BR>";
foreach($enum_options as $value) echo "-$value<BR>";

echo "<P>";

array_pop($enum_options);

echo "ENUM options without the default value:<BR>";
foreach($enum_options as $value) echo "-$value<BR>";
?>


I would really appreciate it if someone could steer me in the right direction.

Mark
 
Old November 3rd, 2003, 02:50 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, the variable $enum_options doesn't exist before you're passing it to array_push, so PHP is complaining that you're not sending an array.

You need to initialize your variables before you use them:

if(!isset($enum_options) || !is_array($enum_options))
{
    $enum_options = array();
}


Take care,

Nik
http://www.bigaction.org/
 
Old January 26th, 2004, 07:51 PM
Registered User
 
Join Date: Jan 2004
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by nikolai
 Well, the variable $enum_options doesn't exist before you're passing it to array_push, so PHP is complaining that you're not sending an array.

You need to initialize your variables before you use them:

if(!isset($enum_options) || !is_array($enum_options))
{
    $enum_options = array();
}


Take care,

Nik
http://www.bigaction.org/

Great :-(
How do you initialize your variables before you use them?

Where do you stick your coding?

The book does not make this clear as I have the same error as the thurmma.

The issue is the countries to be selected in the form. In my case the form shows a blank list of countries.

My question: do we just add a list of countries options? or are they included from a simple text file.

 
Old January 27th, 2004, 04:26 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, it only makes sense to have a variable already in existence if you're going to compare it to some other value. PHP issues a NOTICE level warning that you can suppress if you want to -- just set error_reporting to "E_ALL & ~E_NOTICE" (in English: "Report all errors except E_NOTICE").

However, initializing variables is easy:

if (! isset($var)) { $var = ''; } // string
if (! isset($var)) { $var = array(); } // array
if (! isset($var)) { $var = 0; } // int
if (! isset($var)) { $var = 0.0; } // float
if (! isset($var)) { $var = FALSE; } // boolean


As far as where you get your list of countries, I would imagine that this info comes with your user viewer script in the book. I don't have the book, nor do I have the code for it, nor do I have the time to download it and look through it.

If you don't have the list of countries, I suggest you create a database table that stores all the countries you're interested in, and use that table to generate whatever you need -- be it an HTML <select> dropdown, or a PHP array, whatever.


Take care,

Nik
http://www.bigaction.org/





Similar Threads
Thread Thread Starter Forum Replies Last Post
ch 13 - sketcher menu problem zamontgo BOOK: Ivor Horton's Beginning Visual C++ 2005 0 May 24th, 2008 10:11 PM
Ch.13 Builing a Shopping Cart seannie BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 3 February 7th, 2007 10:11 AM





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