faqts : Computers : Programming : Languages : PHP : Common Problems : Forms and User Input

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

47 of 53 people (89%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

I used "echo($value)" to parse value from a form submission but nothing is displayed. How can I display the "value" input from form submission?

May 11th, 2002 16:23
Philip Olson, Abe J-son, Teerapan Thongampai,


Have a look here :
   http://www.php.net/manual/en/function.echo.php
If the form is has something like this :
   <input type="text" name="foo">
There are a few ways to echo it out, here they are:
   echo $foo;
   echo "hello, this is $foo and it is nice";
   echo 'hello, this is ' . $foo . ' it is nice';
But, this behavoir used to be default in PHP but as of PHP 4.2.0 the PHP
directive register_globals = off.  This means that $foo will not exist
automagically.
   http://www.php.net/manual/en/configuration.php#ini.register-globals
It's more portable to assume register_globals = off and go through other
means.  One example is PHP has many predefined variables that contain a
lot of information.  For example, if we used method="GET" in our form
we'd do:
   echo $HTTP_GET_VARS["foo"];
$HTTP_GET_VARS is a predefined variable, this assumes you are using GET 
method with the form.  $HTTP_POST_VARS works for post methods, read 
about predefined variables here :
   http://www.php.net/manual/en/language.variables.predefined.php
As of PHP 4.1.0 there are additional features, such as superglobals. 
They can be read about in the above manual page too, along with
functions extract() and import_request_variables().  Examples:
   print $_REQUEST['foo'];
   import_request_variables('gpc', 'r_');
   print $r_foo;
   if (!ini_get('register_globals')) {
     extract($HTTP_SERVER_VARS);
   }
   print $HTTP_REFERER;