|
Posted by Neil on 10/02/05 01:04
I'm trying to assign values from an array to variables within my PHP script,
but just can't get the syntax right.
Here is my original code snippet:
---- PHP -----
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";
}
}
----------PHP-------
I am sending this test PHP script values from:
<HTML> <!-- HTML Form -->
<Body>
<form action="test.php" method="post">
Name: <input type="text" name="name"><br>
Email: <input type="text" name="email"><br>
Message: <textarea name="message"></textarea><br>
<input type="submit" name="submit" value="Submit Form">
</form>
</body>
</HTML>
Should I just be able to use?:
list($name,$email,$message) = $arrayname Should I create an
array name? My array doesn't seem to be named.
For reference, this is my entire PHP script:
<?PHP
$to = "email@domain.com"; #set address to send form to
$subject = "Results from your test PHP script "; #email subject line
$headers = "From: Your Site"; #set the from address, or any other headers
$forward = 1; # redirect once email is sent? 1 : yes || 0 : no
$location = "referralpage.htm"; #set page to redirect to, if 1 is above
## Adds time and date to the email ##
$date = date ("l, F jS, Y");
$time = date ("h:i A");
## the message part of the email ##
$msg = "Below is the result of your feedback form. It was submitted on $date
at $time.\n\n";
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";
}
}
mail($to, $subject, $msg, $headers);
if ($forward == 1) {
header ("Location:$location");
}
else {
echo "Thank you for submitting our form. We will get back to you as soon
as possible.";
}
?>
I hope this enough information to understand my question. thanks
Navigation:
[Reply to this message]
|