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, 07:13 AM
Registered User
 
Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default register_golbals off

Hello:
I am unable to display the results of the tryouts of Chapter 3 on forms.
I am using Mac OSX 2.8 and PHP 4.3.4-2 from entropy and in this version register_globlas are off by default and is not recommended to turn it on.
Is there a workaround for this problem?
Please be extensive in your answers; I am a newbie.
Thanks,
Dudu.
 
Old April 19th, 2004, 07:55 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

register_globals more or less takes data from a variety of named sources and combines all of it to be available in the global variable namespace. Data from HTML forms, server and enviornment variables, data from cookies and sessions.

If an HTML form has a method of POST and contains the following field:
<input type='text' name='some_variable' value='Hello, World!' />

With register_globals = On it is available in PHP as:
$some_variable

With register_globals = Off it is available in PHP as:
$_POST['some_variable']

Its an indice inside of the $_POST array instead of a normal global. This is a good thing since in the following scenario, you wouldn't be able to tell if $some_variable came from GET, POST, etc.

Using the same HTML form with a GET method:
With register_globals = On it is available in PHP as:
$some_variable

With register_globals = Off it is available in PHP as:
$_GET['some_variable']

Do you see why there are problems with it being on?

Anyhow have a look at Nik's FAQ which discusses this more in depth.
http://p2p.wrox.com/archive/beginnin...2002-11/17.asp

hth,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old April 29th, 2004, 07:13 AM
Registered User
 
Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your help, I have another question:
I want to pass an array to another page and I don't know how to:

<FORM METHOD=GET ACTION="dynamic2.php">
<?php
for ($Counter=0; $Counter<$_POST["Number"]; $Counter++)
{
   $Offset = $Counter+1;
   echo "<BR><BR>Please enter the name of child number $Offset<BR>";
   echo "<INPUT NAME=Child[] TYPE=TEXT>";
}
if ($Counter==0) echo"Press the button to move on";
?>

The array is Child[ ]. I want to pass it to another page and also use it in an echo statement.

Thanks,

Eduardo

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

My suggestion is to use the POST method for passing arrays, though the values would probably get passed via GET. I hate this book's examples!

   echo "<INPUT NAME='Child[]' TYPE='TEXT'>";

On the next page you'd access the array as $_GET['Child'][$count], as PHP creates a multideminsional array.

Does this help?

Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old April 30th, 2004, 07:26 AM
Registered User
 
Join Date: Jul 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello:
To complement my previous post, what I actually want is to to have this code in this page, but the code in the book is old and I don't know how to solve the problem passing the array: Child [ ].
Here is the old code from the book.

<?php
$Count=0
echo "Your children's name are: ";
do
{
echo "<BR><BR>$Child[$Count]";
$CheckEmpty="$Child[$Count]";
$Count=$Count+1;
}While ($CheckEmpty!=" ");
if ($Count==1) echo "Not Applicable";
?>

Thanks for your help.

 
Old April 30th, 2004, 07:50 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 really a horrible example of a do/while loop.

Have a look at this alternative:

Code:
<?php

    if (isset($_GET['Child']) && is_array($_GET['Child']))
    {
        foreach ($_GET['Child'] as $kid)
        {
            echo $kid.'<br />';
        }    
    }
    else
    {
        echo "Screw you man! I didn't want to know your kid's names anyway!";
    }

?>
Basically it says if $_GET['Child'] exists, and it is an array iterate through each index of the array with foreach assign each value to the variable $kid and then print out the value. If it doesn't exist, well, it insults you ;). This works if you're using the GET method to post your form, if you're using the post method, use the $_POST superglobal instead.

hth!




Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::
 
Old April 30th, 2004, 07:54 AM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

BTW: if you really want to see the book's example do this:

<?php
$Count=0;
echo "Your children's name are: ";
do
{
echo "<BR><BR>".$_GET['Child'][$Count];
$CheckEmpty=$_GET['Child'][$Count];
$Count=$Count+1;
}While ($CheckEmpty!=" ");
if ($Count==1) echo "Not Applicable";
?>

My example does the same thing, but with less gunk.

Regards,
Rich

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









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