Help (PHP)

Associate
Joined
3 Oct 2003
Posts
611
Location
Northampton,UK
Hi guys,

Iv'e started to learn php today and i have run into a few problems.

Im following a php book and have tryed an simple php html form example.

I have made 2 pages one html page with input forms and a php page which outputs the variables that the user entered. The code for both is:

<HTML>

<HEAD>
<TITLE> HTML TEST FORM </TITLE>
</HEAD>

<BODY>

<FORM ACTION="HandleForm.php" METHOD="POST">

FIRST NAME <INPUT TYPE=TEXT
NAME="FirstName" SIZE=20><br>

Last Name <INPUT TYPE=TEXT
NAME="LastName" Size=40><br>

E-mail Address <INPUT TYPE=TEXT
NAME="Email" SIZE=60><br>

Comments <TEXTAREA NAME="Comments" ROWS=5 COLS=40></TEXTAREA><br>
<br>

<INPUT TYPE=SUBMIT NAME="SUBMIT" VALUE="Submit!"

</FORM>
</BODY>
</HTML>

And the php page that handles the information is suppost to just echo the data back to the user:

<html>

<title> Results </title>

<?php echo $FirstName; ?>
<?php echo $LastName; ?>
<?php echo $Email; ?>
<?php echo $Comments; ?>


</html>

However when running these and clicking submit no data is displayed on the screen as if the variables are empty!

What have i done wrong!

Cheers,

Eddie
 
Firstly, please use code tags when posting code :)

The problem you are experiencing is related to the register_globals directive.

Namely, the book assumes your PHP installation will have this enabled, which in many peoples opinions is a no no, and register_globals is actually disabled by default.

A better way to access any POST variables (your form is using POST as the method of transferring request data), you can access them in the $_POST superglobal array, like so:
Code:
<?php
  echo $_POST['FirstName'];
  echo $_POST['LastName'];
  echo $_POST['Email'];
  echo $_POST['Comments'];
?>

There is more to it, including security, but that should get you started :)

Add <br />\n to the end of the echo to seperate each variable onto a new line if needed :)
Code:
<?php
  echo $_POST['FirstName'] . "<br />\n";
?>
 
Back
Top Bottom