Posted by Tyrone Slothrop on 10/02/05 05:56
On Sat, 1 Oct 2005 17:04:54 -0500, "Neil" <nomailplease@mail.com>
wrote:
>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.
The array name is $_POST. You don't need the $_GET code in there.
You can use list but it is not as reliable as what you have since the
order of the fields is very important.
[Back to original message]
|