Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP creating Strings from forms - not 1

Status
Not open for further replies.

BadChough

Programmer
Dec 20, 2007
137
GB
In a textbook on PHP 4 I am advised that the PHP Script engine will create a String from the suffix of the URL sent to a .php page from a GET instruction.( in this case "?Author=whoever")
The example given is as follows:

First Page:
<html>
<head></head>
<body>
<form method="get" action="text.php">
Who is your favourite author?
<input name="Author" type="text">
</br>
</br>
<input type="submit" value="Submit">
</form>
</body>
</html>

Second page (text.php) :
<html>
<head></head>
<body>
Your favourite author is :
<?php
echo $Author ;
?>
</body>
</html>

The output is a disappointing "Your favourite author is :" and nothing more.
Is the book wrong, or perhaps PHP 5, which I am using, no longer functions in this way?
 
You are a victim of poorly written books that rely on register_globals being set to on.

register_globals is a PHP setting that allows exactly what you describe, to make form fields into PHP variables automagically.

For security reasons it was suggested to be set to off in older versions and has been set to off by default in more recent versions of PHP.

It is strongly suggested you keep it off, and instead use the predefined super global variables to access the data from html forms. Depending on the method of posting data you have set your form to will be the variable to use.

In your case, since your form is using the GET method you want to do thew following:
Code:
echo $_GET['Author'] ;






----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks for your clear explanation, vacunita.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top