Click to See Complete Forum and Search --> : Beginner PHP Help


nko
12-16-2003, 02:34 AM
I feel like a jerk asking a question that's probably been asked a million times, but I'm not sure how I'd search for this problem, so I'm posting it here :-)

I started looking in to PHP today. I'm trying to set up an HTML form that passes a single text string to a form-handling PHP page.

This is my HTML form:

<html>
<head><title>Test PHP Form</title></head>
<body>

<form action="formhandler.php" method="post">
First Name <input type="text" name="FirstName" size="20">
<input type="submit" name="submit" value="Submit">
</form>

</body>
</html>

This is the handler to which it refers:

<html>
<head>
<title>Handler</title>
</head>
<body>
<?php

print("Hello, $FirstName");

?>
</body>
</html>

It invariably produces the following output:

Hello,

Any idea what I'm doing wrong? If it helps, it's being served on the local machine. Apache's the server. I've also tried the GET method, but it didn't change anything.

Thanks!

nko
12-16-2003, 03:20 AM
Wow, nevermind, it just *happens* that this question was just asked, and answered RIGHT before I asked! Mod me down, please.

For those interested, I had the same book as the other guy who asked, appearantly, which is outdated, though fairly new. The fix is to refer to variables in the form handling PHP script as $_POST[variablename].

Thanks, guys in the other topic!!

aeav
12-18-2003, 12:39 AM
Or if you prefer to use variables, have this mod:


<?
$firstname = $HTTP_POST_VARS["FirstName"]; /* Here the form variable of the first name */

print("Hello, $firstname");

?>