0

My PHP will not work. I'm trying to use $_POST to collect information from the form and nothing is coming up.

Here is the HTML code:

<form action="test2.php" method="post">                                         
    First Name:<br />
    <input type="text" name="firstname" /><br />
    Last Name:<br />
    <input type="text" name="lastname" /><br /><br /><br />
    Address:<br />
    <input type="text" name="address" /><br />
    City:<br />
    <input type="text" name="City" /><br />
    Province:<br />
    <input type="text" name="province" /><br /><br /><br />
    Phone:<br />
    <input type="text" name="phone" /><br />
    Email<br />
    <input type="text" name="email" /><br /><br /><br />
    Select Desired Apartment: <br />
    <input type="checkbox" name="type" value="onebed" />One Bedroom<br />
    <input type="checkbox" name="type" value="twobed" />Two Bedroom<br />
    <input type="checkbox" name="type" value="threebed" />Three Bedroom<br /><br /><br />
    Rental Type:<br />
    <input type="radio" name="renttype" value="weekly" />Weekly<br />
    <input type="radio" name="renttype" value="monthly" />Monthly<br /><br /><br />
    Start Date:<br /><input type="date" name="startingdate" /><br /><br /><br />
    <input type="submit" value="Submit" />
</form>

Here is test2.php

<!DOCTYPE HTML>
<html>
    <body>
    Registration_Number: <br /> 
    Name: <?php echo $_POST['firstname']; ?> <br />
    Address: <?php echo $_POST['address']; ?> <br /> 
    Email: <?php echo $_POST['email']; ?> <br />
    Appartment_Type: <br />
    Rental_Type: <br />
    Starting_Date: <?php echo $_POST['startingdate']; ?> <br />
    </body>
</html>

Thanks for the help!

18
  • 2
    Define not working! What is the error you get? Commented Nov 15, 2014 at 19:55
  • Use this for error reporting: <?php error_reporting(E_ALL); ini_set("display_errors", 1); ?> And it works fine for me! Commented Nov 15, 2014 at 19:56
  • 1
    Are you sure you have PHP installed and configured properly? Commented Nov 15, 2014 at 19:56
  • After I fill out the form and submit it, it loads the php page and where the $_POST should be shown it is blank. Commented Nov 15, 2014 at 19:57
  • 1
    If you can't see the output of $_POST, try var_dump($_SERVER);. That should output something. Otherwise, there might be something wrong with your server or PHP install. Your HTML/PHP seems to check out fine. Commented Nov 15, 2014 at 20:02

2 Answers 2

1

First assure php is working properly

create a test php file with this

<?php
 echo "it's working";

and navigate to it using the browser

it should show the message it's working


Second step is assuring everything is working with your form.

change your test2.php to this:

<?php
error_reporting(E_ALL); 
ini_set("display_errors", 1);
var_dump($_POST);

you should see the values of the form posted

Sign up to request clarification or add additional context in comments.

Comments

0

try adding value attributes to all your input tags. Sometimes browsers will not send these fields. You would see a blank page if you do not have PHP configured to display errors.

<form action="test2.php" method="post">                                         
    First Name:<br />
    <input type="text" name="firstname" value="" /><br />
    Last Name:<br />
    <input type="text" name="lastname" value="" /><br /><br /><br />
    Address:<br />
    <input type="text" name="address" value="" /><br />
    City:<br />
    <input type="text" name="City" value="" /><br />
    Province:<br />
    <input type="text" name="province" value="" /><br /><br /><br />
    Phone:<br />
    <input type="text" name="phone" value="" /><br />
    Email<br />
    <input type="text" name="email" value="" /><br /><br /><br />
    Select Desired Apartment: <br />
    <input type="checkbox" name="type" value="onebed" />One Bedroom<br />
    <input type="checkbox" name="type" value="twobed" />Two Bedroom<br />
    <input type="checkbox" name="type" value="threebed" />Three Bedroom<br /><br /><br />
    Rental Type:<br />
    <input type="radio" name="renttype" value="weekly" />Weekly<br />
    <input type="radio" name="renttype" value="monthly" />Monthly<br /><br /><br />
    Start Date:<br /><input type="date" name="startingdate" value="" /><br /><br /><br />
    <input type="submit" value="Submit" />
</form>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.