help with forms

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
gammaman
Forum Commoner
Posts: 45
Joined: Tue Feb 12, 2008 9:22 am

help with forms

Post 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.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: help with forms

Post 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;!
Post Reply