Click to See Complete Forum and Search --> : PHP + Forms=?


Arithan
03-04-2003, 07:51 PM
My web server doesn't store form values!
I used the following test script:

<?php
if(!isset($TestFeild))
{
//The form hasn't been submitted yet
//Show it
?>
<form method="post" action="form_test.php">
<input name="TestField" type="text">
<input name="submit" type="submit" value="Submit">
</form>
<?php
}
else
{
//Show results
echo "You have entered " . $TestField . " into the field";
}
?>

When you type something into the textbox and submit the page is shown again!
Why? I assume this is a configuration problem. Can someone help me please!

cgraz
03-04-2003, 10:53 PM
Your web server isn't the problem, it has globals set to off (which is the default). That means, to access POST variables, you need to use $_POST

For example:

if(!isset($TestFeild))

should be

if(!isset($_POST['TestFeild']))

and your echo should look like


echo "You have entered " . $_POST['TestField'] . " into the field";

Cgraz

Arithan
03-04-2003, 11:20 PM
Thanks. I had no idea

Arithan
03-04-2003, 11:30 PM
K, here is the fixed code:

<?php
if(!isset($_POST['$TestField']))
{
//The form hasn't been submitted yet
//Show it
?>
<form method="post" action="form_test.php">
<input name="TestField" type="text">
<input name="submit" type="submit" value="Submit">
</form>
<?php
}
else
{
//Show results
echo "You have entered " . $_POST['$TestField'] . " into the field";
}
?>

It still doesn't display the else clause
Any ideas why?

cgraz
03-04-2003, 11:32 PM
Take a look at my previous post.

You're using

if(!isset($_POST['$TestField']))

when it should be

if(!isset($_POST['TestFeild']))

Cgraz

Arithan
03-04-2003, 11:45 PM
I fixed it already, but i forgot to repost. I also changed the order of the variables (variable_order directive) to EPGCS, so now i can use the post variables anyway, but thanks for the input.