Frustrated

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Gimpy
Forum Commoner
Posts: 42
Joined: Tue Jun 14, 2005 1:12 am
Location: Fort Worth, TX, US
Contact:

Frustrated

Post 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 :)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: Frustrated

Post 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
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Gimpy
Forum Commoner
Posts: 42
Joined: Tue Jun 14, 2005 1:12 am
Location: Fort Worth, TX, US
Contact:

Re: Frustrated

Post 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?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: Frustrated

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
InsanityNet
Forum Newbie
Posts: 6
Joined: Mon Oct 25, 2010 12:37 pm

Re: Frustrated

Post 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
}
?>
Post Reply