|
Posted by David Cartwright on 10/09/05 15:21
"gregsands" <saunders1@gmail.com> wrote in message
news:1128795955.726995.326190@g43g2000cwa.googlegroups.com...
> Help! ive been happily coding away for hours only to get a 'Notice:
> Undefined variable' error. I switched off the error reporting in
> php.ini then created a helloworld.php file to check i wasnt going
> crazy, but i am!
> my helloworld.php file looks like this :
> <?php
> echo ("Hello $word !");
> ?>
You can't refer to HTML form variables in this way unless you explicitly
tell PHP to give you them. There are two popular ways to get at form
variables:
1. Built-in variable sets
Historically, you have been able to refer to form variables using
$HTTP_POST_VARS (for POST forms) or $HTTP_GET_VARS (for GET requests like
the one you described). So your variable would be referred to as
$HTTP_GET_VARS["word"]. Since 4.1.0 there's a shorthand - you can use
$_GET["word"]. Incidentally, if you use a mix of GET and POST forms, you can
get at stuff as $_REQUEST["word"].
2. import_request_variables
PHP can be told to import form variables and make them PHP variables in
their own right. This is the approach I use mostly. If, at the start of your
script, you say:
import_request_variables("gp","form_")
.... it will take all GET and POST (the "gp") variables and make them into
PHP variables in their own right, prefixing them (in this case) with "form_"
so that they don't inadvertently trample on variables in your script with
the same name. So in your example you'd refer to $form_word.
HTH,
D.
Navigation:
[Reply to this message]
|