/    Sign up×
Community /Pin to ProfileBookmark

What does this script mean:

[QUOTE]

$msg = “Below is the result of your feedback form. It was submitted on $date at $time.nn”;

if ($_SERVER[‘REQUEST_METHOD’] == “POST”) {
foreach ($_
POST as $key => $value) {
$msg .= ucfirst ($key) .” : “. $value . “n”;
}
}
else {
foreach ($_GET as $key => $value) {
$msg .= ucfirst ($key) .” : “. $value . “n”;
}
}

[/QUOTE]

I have no idea about the logic of how this works, if anyone could explain to me about this script, PLEASE HELP!
This is a piece of the original script off of [url]http://webdevfaqs.com/php.php#mailer[/url]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@mwiggin1Jun 18.2004 — This is checking to see if a form was submitted to this page using the "GET" method or the "POST" method and then it is using the "foreach" method of the Array class to list all of the elements that were posted ... in this format:

Element_name:value

When form data is posted, it is posted as an associative array ... meaning that it is an array indexed by keywords like this example:

$HTTP_POST_VARS("name") [i]= "jimbo"[/i]

$HTTP_POST_VARS("email") [i]= "[email protected]"[/i]

etc ...

so using foreach:

"$_POST as $key" is set to the name or "index" (name, email) of the of the array element and "$value" is set to the value of the array element (jimbo, [email][email protected][/email])

get it?
×

Success!

Help @theuedimaster 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.5,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

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