Page 1 of 1

help with forms

Posted: Mon Feb 25, 2008 3:20 pm
by gammaman
I need help with a form that allows the user to enter and submit the information, and then that information that they enter is automatically dislplayed below on the same page, after they hit the submit button. Here is the code I have.

Here is the html code (comment.html)

***** PLEASE USE THE CODE TAG WHEN POSTING *****

Code: Select all

<html>
<body>
<form action="post.php" method="post">
First Name:
<input type ="text" name="firstname"/>
&nbsp
Last Name:
<input type ="text" name="lastname"/>
<br/>
<br/><dd/>
Comments orSuggestions:
<br/><dd/>
<textarea name="comment" rows="10" cols="50"></textarea>
</textarea>
 
</form>
</body>
</html>
Here is the php code (post.php)

Code: Select all

<?php
$firstname=$_GET['firstname'];
$lastname=$_GET['lastname'];
$comment=$_GET['comment'];
 
echo $firstname;
echo "&4nbsp; $lastname";
echo ":";
echo "&nbsp; $comment";
?>
I do not want the the info when submitted to be displayed on the php page, I want it displayed on the html page where it was submitted, I was told I needed a php page to do that, but I cannot get it to work.

Re: help with forms

Posted: Mon Feb 25, 2008 4:34 pm
by andym01480
Your form method=post and you are trying to retrieve the form fields in the php script using $_GET. Change it to $_POST.
$_GET is used when the form method is Get which appends them to the url... eg index.php?firstname=andy&lastname=moyle

You also have a typo in one of the &nbsp;!