Click to See Complete Forum and Search --> : variables passing doesn't work


discus
08-08-2005, 02:07 PM
Hello,

Could you help me with this problem please?
In which way should I use the following 2 scripts:

Listing 10-2: A simple form
<html>
<head>
<title>Listing 10-2</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#cbda74" vlink="#808040"
alink="#808040">
<form action="listing10-3.php" method="post">
<b>Give us some information!</b><br>
Your Name:<br>
<input type="text" name="name" size="20" maxlength="20" value=""><br>
Your Email:<br>
<input type="text" name="email" size="20" maxlength="40" value=""><br>
<input type="submit" value="go!">
</form>
</body>
</html>

Listing 10-3: Displaying the data collected in Listing 10-2
<html>
<head>
<title>Listing 10-3</title>
</head>
<body bgcolor="#ffffff" text="#000000" link="#cbda74" vlink="#808040"
alink="#808040">
<?
// output the user's name and email address.
print "Hi, $name!. Your email address is $email";
?>
</body>
</html>

I've saved them as a 2 php files, listing10-2.php and listing10-3.php in my localhost folder.
I've called listing10-2.php through my localhost, and have got the form.
When I fill the form and press the 'go!' button, I get "Hi, !. Your email address is".
So why the variables $name and $email haven't been passed ?



Thanks

neil9999
08-08-2005, 02:23 PM
Hi discus,

Use print "Hi, ".$_POST['name']."!. Your email address is ".$_POST['email'];

If you used the get method then you'd use $_GET['name']

Hope that helps,

Neil

discus
08-08-2005, 03:09 PM
Thanks Neil.

That has helped indeed.

But I'm just wondering why the author of this book (Programmers Introduction To PHP4) W.J.Gilmore, didn't put that in the script ?
Is that something about PHP versions (maybe newer versions require that, and older ones not)?


Greetings

grailquester5
08-08-2005, 03:29 PM
It's actually dependent on the "register globals" setting on the server. With "register globals" enabled, you could use "$name" and "$email". "Register globals" was ON by default in PHP versions before 4.2, and OFF by default after. With "Register globals" OFF, you have to use the Superglobal arrays $_POST[], $_GET[], $_REQUEST[], etc. If you want to check the server configuration, just create a quick PHP script like this and it will reveal most everything:

<?php

echo phpinfo();

?>

discus
08-09-2005, 03:10 AM
Thanks grailquester