/    Sign up×
Community /Pin to ProfileBookmark

parameter transferrance

I see from a php manual that php variable could transfer in different pages, so I wrote the following two pages:
1.submit.php
<form name=”form” method=”post” action=”adds.php”>
<input name=”name” type=”text”>
<input type=”submit” name=”submit” value=”submit”>
</form>
2.adds.php
<? php echo $name; ?>
In the first one,it generated a variable “$name” automatically,
but why the second adds.php show nothing on the page?

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@96turnerriJul 01.2004 — [code=php]<?php echo $name; ?>[/code]

should be

[code=php]<?php echo $_POST["name"]; ?>[/code]

if you then go to another page after adds.php variable post will not be stored anymore

you will need to set it as a session variable or a cookie

http://uk2.php.net/manual/en/function.setcookie.php

http://uk.php.net/manual/en/ref.session.php

[COLOR=red]EDIT:[/COLOR] ooops didnt see that its <?php not <? php damn forum formating
Copy linkTweet thisAlerts:
@nobyauthorJul 01.2004 — I have tried your way, but IE showed :"Parse error: parse error, unexpected T_ECHO in E:bbs2adds.php on line 1".

Do You mean that if I want to use a variable from different page, I must set a cookie or use session?
Copy linkTweet thisAlerts:
@Paul_JrJul 01.2004 — Unless the [font=courier]register_globals[/font] directive is set (I believe it isn't by default), then you access values passed to the page from the HTTP POST method through the $_POST superglobal (or $HTTP_POST_VARS for PHP versions earlier than 4.1.0).

So
[code=php]
<?php
echo $_POST['name'];
?>
[/code]

Or, if you are running PHP v. < 4.1.0
[code=php]
<?php
echo $HTTP_POST_VARS['name'];
?>
[/code]

You can find some more information <[url=http://www.php.net/manual/en/language.variables.predefined.php]here[/url]>
Copy linkTweet thisAlerts:
@shimonJul 01.2004 — [i]Originally posted by noby [/i]

[B]IE showed :"Parse error: parse error, unexpected T_ECHO in E:bbs2adds.php on line 1".[/B][/QUOTE]


because there shouldn't be a space between '<?' and 'php'.

so:[code=php]<?php

// code here

?>[/code]
×

Success!

Help @noby 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...