/    Sign up×
Community /Pin to ProfileBookmark

variables passing doesn’t work

Hello,

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

[b]Listing 10-2: A simple form[/b]

[code=php]<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>[/code]

[b]Listing 10-3: Displaying the data collected in Listing 10-2[/b]

[code=php]<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>[/code]

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

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@neil9999Aug 08.2005 — Hi discus,

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

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

Hope that helps,

Neil
Copy linkTweet thisAlerts:
@discusauthorAug 08.2005 — 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
Copy linkTweet thisAlerts:
@grailquester5Aug 08.2005 — 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:
[code=php]
<?php

echo phpinfo();

?>
[/code]
Copy linkTweet thisAlerts:
@discusauthorAug 09.2005 — Thanks grailquester
×

Success!

Help @discus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...