PHP not echoing information from HTML form

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
Marc_Designer
Forum Newbie
Posts: 1
Joined: Thu Jul 22, 2010 11:23 am

PHP not echoing information from HTML form

Post by Marc_Designer »

Hi everyone,

I'm new to PHP and have come up against my first problem so thought I'd join this site to see if anyone can shed any light on the matter.

I'm currently designing and bulding a new website for myself and have succsessfully built the homepage and uploaded it to my domain space. I have a contact form which I've coded with HTML and styled with CSS and wanted to test the form fields are working by echoing out some of the data to the browser. However when the submit button is clicked the browser is directed to the 'contactform.php' page but it appears blank. Here is the respective code I have set up:

HTML form code:

<div id="formscontainer"><!------ Centering Form Container -->

<div id="formcolumnone"><!------ First Column -->

<div id="formlogo">
<a href="#"><img src="images/contactformlogo.png" title="Back to the homepage" border="none"/></a>
</div>

<div id="requiredfields"><!------ Required Info-->
<h1><font color="#FFFF00">Required fields marked with a*</font></h1>
</div><!------ End Required Info -->

<div id="leftform"><!------ Left Hand Form -->

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

<fieldset class="first">
<label id="namefield" for="name">
<input type="text" id="name" name="name" value="*Name" />
</label>

<label id="emailfield" for="email">
<input type="text" id="name" name="email" value="*Email" />
</label>

<label id="websitefield" for="website">
<input type="text" id="website" name="website" value="*Website" />
</label>

</fieldset>
</form>

</div><!------ End Left Hand Form -->

</div><!------ End First Column -->

<div id="formcolumntwo"><!------ Second Column -->

<div id="rightform"><!------ Right Hand Form -->

<form action="contactform.php" method"post">
<fieldset class="second">
<label id="subject" for="subject">
<input type="text" id="subject" name="subject" value="*Subject" />
</label>

<label class="labelFive" >
<textarea ROWS="8" COLS="49" name="enquiry">*Enquiry</textarea>
</label>

</fieldset>
</form>

</div><!------ End Right Hand Form -->

</div><!------ End Second Column -->

<div id="formcolumnthree">

<div id="closeformbutton"><!------ Header Phone Number -->
<a href="#" title="You sure you don't want some Lemmonaid?"><h1><font color="#FFFF00">Close</font></h1></a>
</div><!------ End Header Phone Number -->

<div id="formbuttons">

<div id="resetbutton">
<form action="contactform.php" method"post">
<button type="reset" input type="reset" id="clear" action="reset form" style="border: 0; background: transparent"><img src="images/resetbutton.png" alt="submit" /></button>
</form>
</div>

<div id="submitbutton">
<form action="contactform.php" method"post">
<button type="submit" input type="submit" id="submit" action="submit form" style="border: 0; background: transparent"><img src="images/submitbutton.png" alt="submit" /></button>
</form>
</div>

</div>

</div>

</div><!------ End Centring Form Container -->

PHP code (to echo out just the name and email data for testing purposes):

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$website = $_POST['website'];
$subject = $_POST['subject'];
$enquiry = $_POST['enquiry'];

echo $name.'<br>' . $email;


?>

I would greatly appreciate any help and advice that anyone might be able to provide.

Thanks in advance.

Marc
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: PHP not echoing information from HTML form

Post by AbraCadaver »

You have multiple forms on your page and only two have buttons and they have no other inputs. Your submit button needs to be inside the form that has the inputs that you want to submit.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: PHP not echoing information from HTML form

Post by JakeJ »

One thing to check for is that if you're using Internet Explorer and uploading that to a place other than a local machine, IE's privacy policy might be prventing the $_POST values from being passed on.

ALSO, since you're new to the site you might not know, but please put all code between tags by clicking the PHP Code button. It helps with formatting and make it easier for us to read it and help you.
Post Reply