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 14th, 2004, 03:39 AM
Registered User
 
Join Date: Apr 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Beginning PHP: Error Report

In Chapter 3 of the Book Begining PHP, i have been accessing using $_GET, but each time I use a quotation in front of echo, it brings an erro. So I have to put my statement before echo, and just put the variable i want to display after echo i.e. What is your name
echo $_GET["name"];
And it works this way.

But further down with LIST boxes, it was always bringing this error message when trying the codes:Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\Inetpub\wwwroot\listbox.php on line 5.

When I manipulated the following codes as the one in the book was giving me error:
<html>
<head></head>
<body>
Price Range:
<?php
echo $_GET['Price'];
?>
Engine Size(s):
<?php
echo $_GET['EngineSize[0]'];
echo $_GET['EngineSize[1]'];
echo $_GET['EngineSize[2]'];
echo $_GET['EngineSize[3]'];
?>
</body>
</html>

Then as I tugg to the browser upon request, it brought the following response:

Price Range: $5,000-$10,000Engine Size(s):
Notice: Undefined index: EngineSize[0] in C:\Inetpub\wwwroot\listbox.php on line 10

Notice: Undefined index: EngineSize[1] in C:\Inetpub\wwwroot\listbox.php on line 11

Notice: Undefined index: EngineSize[2] in C:\Inetpub\wwwroot\listbox.php on line 12

Notice: Undefined index: EngineSize[3] in C:\Inetpub\wwwroot\listbox.php on line 13

I tried the new instruction that we should access data via superglobal arrays using the following code:<html>
<head></head>
<body>
Price Range:
Engine Size(s):
<?php
echo $_GET['Price'];
echo $_GET['EngineSize[0]'];
echo $_GET['EngineSize[1]'];
echo $_GET['EngineSize[2]'];
echo $_GET['EngineSize[3]'];
?>
</body>
</html>

It gave me the following response:
Price Range: Engine Size(s): $5,000-$10,000
Notice: Undefined index: EngineSize[0] in C:\Inetpub\wwwroot\listbox.php on line 8

Notice: Undefined index: EngineSize[1] in C:\Inetpub\wwwroot\listbox.php on line 9

Notice: Undefined index: EngineSize[2] in C:\Inetpub\wwwroot\listbox.php on line 10

Notice: Undefined index: EngineSize[3] in C:\Inetpub\wwwroot\listbox.php on line 11

Also further down using the hidden fields, the info was fully displayed as against the directive to hide them i.e. "Bugs Bunny", "Homer Simpson", "Reny & Stimpy". Also as I click the submit button, it gives an error "Undifined Variables"

Please look into all these observation, as they are really slowing me down. I am still a babie in PHP.

Daniel


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

This is a common misconception, multi-dimensional arrays are formed by appending additional levels. Since $_GET is already an array, extra levels are just appended to the end.

Take for instance the following query string:

/index.php?EngineSide[0]=1

This would be represented with PHP using:

<?php
echo $_GET['EngineSize'][0];
?>

Second before you output a variable or constant you'll want to be sure that it exists first.

if (isset($_GET['EngineSize'][0]))
{
    echo $_GET['EngineSize'][0];
}

PHP will temporarily create a copy of the variable in memory will null value if the variable does not exist and you try to use it. Then it'll spit out a E_NOTICE level error complaining that it didn't exist.

Also, make sure that the method attribute of your HTML form is set to get, because if I remember right this example used the post method. If its set to the post method you'll want to use the $_POST superglobal array instead of $_GET.

hth,
Rich

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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Beginning PHP everetts Beginning PHP 2 February 10th, 2007 10:51 AM
Beginning PHP Snib Forum and Wrox.com Feedback 4 September 24th, 2004 04:33 PM
Beginning PHP: CH17, PHP Directory cyberjacky Beginning PHP 1 March 12th, 2004 11:39 AM
Beginning PHP Chapter 3- gbengadaniel Beginning PHP 1 January 25th, 2004 05:19 PM
BEGINNING PHP 4 Jacek Hibner Wrox Book Feedback 1 August 2nd, 2003 07:08 AM





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