Page 1 of 1

Frustrated

Posted: Mon Oct 25, 2010 9:49 am
by Gimpy
I cant seem to find a place that helps me with this and people here seem like they like to help. I have to questions..

Why is this form not sending the input box?

Code: Select all

<body>
<form method="post"  runat="server" action="test.php">
<input name="name" maxlength="16" />
<input type="submit" value="Submit">
<br />
</form>
<?php 
$name = $_GET['name'];

echo $name
?>
And Second, how do I make this work on this same page AND how do I pass it to another page?
Please help, getting frustrated at php5

thanks :)

Re: Frustrated

Posted: Mon Oct 25, 2010 9:51 am
by s.dot
$_GET['name'] should be $_POST['name'] (since your form method is POST)
You should also check that the form has been submitted before you check for the name

Re: Frustrated

Posted: Mon Oct 25, 2010 9:57 am
by Gimpy
Has it always been a post and $_post? and what kind of check are you referring to? That the box is actually populated or that it passes?

Re: Frustrated

Posted: Mon Oct 25, 2010 12:39 pm
by pickle
There are 2 common types of form submission methods, POST, and GET. They are represented in PHP with the $_POST and $_GET superglobal arrays.
Your method in your form is "post", but you're checking $_GET in your PHP code. Change that to $_POST.

When you first load your page, $_POST['name'] won't be set, as the form won't have been submitted. You should check if the "name" element exists in $_POST before accessing & outputing it. Otherwise you'll get an error.

Re: Frustrated

Posted: Mon Oct 25, 2010 1:03 pm
by InsanityNet
Try this:

Code: Select all

<body>
<form method="post"  runat="server" action="test.php">
<input name="name" maxlength="16" />
<input type="submit" value="Submit">
<br />
</form>
<?php 
if (isset($_POST['name'])) {
$name = $_POST['name'];

echo $name
}
?>