tags:

views:

43

answers:

3

Hi, for some reason I cannot get any form to work correctly on my website, I even went to w3school and copied a simple test form to see if it works, and it does not, here it is:

welcome.php:

<?
Welcome <?php echo $_GET["fname"]; ?>!<br />
You are <?php echo $_GET["age"]; ?> years old.
?>

form:

<form action="welcome.php" method="get">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

I'm not sure if it matters or not, but I tried with and without brackets, and still I get a blank page, in explorer I get a 500 Error, most likely causes is maintenance or Programming Error", but I had the same issue last night so I doubt its maintenance, and everything else works.

+2  A: 

Your form uses get and you're reading from $_POST.

Either change html to

<form action="welcome.php" method="post">

or change the php to

Welcome <?php echo $_GET["fname"]; ?>!<br />
You are <?php echo $_GET["age"]; ?> years old.

Also, make sure the value is present using the isset

Welcome <?php echo isset($_GET["fname"]) ? $_GET["fname"] : "Guest"; ?>!<br />
Amarghosh
No that was a typo when I put the question here, I was doing some testing.
Murtez
@Murtez did you try `isset`?
Amarghosh
A: 

When you use $_POST["fname"] you should also specify post as method in your form

welcome.php:

<?
Welcome <?php echo $_POST["fname"]; ?>!<br />
You are <?php echo $_POST["age"]; ?> years old.
?>

form:

<form action="welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
Falle1234
+3  A: 

Remove the beginning <? and ending ?> from your welcome.php.

kingjeffrey
Oops, I even copied that to my answer - still didn't notice it. +1
Amarghosh
LOL yes, I realized that later last night from copying the script over, and it was driving me nuts. I hate it when that happens.
Murtez
Glad I could be of assistance.
kingjeffrey