0

I'm working on a class project and I need a functioning form. I'm trying to get it to work, but every time I hit the submit button, it takes me to a blank page. I know something is wrong, because I found other questions on this topic, but none of the answers there helped. So here's what I've got (an abridged version to condense things):

HTML:

   Email address*:<br> <input type="text" name="email" required>
    <br>
    </fieldset>
    <br>
    <br>
    <fieldset>
        <legend>Room Information</legend>
    Which room would you like us to reserve for you?<br>
      <select name="Room">
        <option value="TeaRoom">The Tea Room</option>
        <option value="CaptainsSuite">The Captain's Suite</option>
        <option value="GreenRoom">The Green Room</option>
        <option value="Valentine">The Valentine Suite</option>
        <option value="Turkish">The Turkish Delight</option>
        <option value="Music">The Music Room</option>
        <option value="Bridal">The Bridal Suite</option>
        <option value="GuestCottage">The Guest Cottage</option>
      </select>
      <br><br>
    How many people are in your party?<br> 
      <input type="radio" name="number" value="1">1<br>
      <input type="radio" name="number" value="2">2<br>
      <input type="radio" name="number" value="3">3<br>
      <input type="radio" name="number" value="4">4<br>
    <br><br>
    Date of Check In:<br> <input type="text" name="checkindate"><br>
    <br>
    Date of Check Out:<br><input type="text" name="checkoutdate">
    <br>
    <br>
    Do you, or anyone in your party, have any special dietary requirements?<br>
    <textarea rows="4" cols="50" name="comment">
    </textarea>
    <br>
    </fieldset>
    <br>
    <br>
      <input type="submit" value="Submit">

PHP:

<?php
$field_name = $_POST['name'];
$field_address = $ POST ['address'];
$field_city = $ POST ['city'];

$field_homephone = $ POST ['homephone'];
$field_cellphone = $ POST ['cellphone'];
$field_email = $_POST ['email'];
$field_Room = $ POST ['Room'];

$field_checkindate = $ POST ['checkindate'];
$field_checkoutdate = $ POST ['checkoutdate'];
$field_comment = $ POST ['comment'];


$radio_button = $_POST['number'];
$drop_down_item = $_POST['state'];



$mail_to = 'email@student.umuc.edu';
$subject = 'Reservation '.$field_name;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
    <script language="javascript" type="text/javascript">
        alert('Thank you for the message. We will contact you shortly with your confirmation.');
        window.location = 'contactpage.html';
    </script>
<?php
}
else { ?>
    <script language="javascript" type="text/javascript">
        alert('Message failed. Please, send an email to eburns15@studentumuc.edu');
        window.location = 'contactpage.html';
    </script>
<?php
}
?>

EDIT: I realize this is a duplicate question. I'm asking this because I want to know specifically what I'm doing wrong, as the question this has been duplicated as does not help me whatsoever.

  • Did you copy/paste your PHP code? If so, replace **all** occurrences of `$ POST` with `$_POST` – rickdenhaan Apr 30 '17 at 21:46
  • Let me introduce you to double quotes. You can change `'From: '.$field_name."\n"` to `"From: $field_name\n"`. That will produce more readable code without the need for concatenation. – Manngo Apr 30 '17 at 21:49
  • rickdenhaan, part of it, yes, part of it I typed it in myself. Anything dealing with codes is an ADHD sufferer's worst nightmare. Geesh! Manngo, you have to forgive me with this, I am a bit slow on the uptake sometimes. When you say change the single quotes in the 'From: etc.' to "From: etc." does that also mean I change the single quotes to double everywhere on this thing? Like I stated, I'm new at this. – Erin T. Aardvark May 01 '17 at 01:39
  • @ErinT.Aardvark The rule is: single quotes for _ininterpreted_ strings, and double quotes for _interpreted_ strings. Interpreted includes special characters (such as `"\n"` as you have used) but also includes variables. For example: `$a=3; print "Amount: $a"; print 'Amount: $a';`. The first `print` will result in `Amount: 3` while the second gives `Amount: $a`. In other words, variables inside double quotes are interpreted, but not those inside single quotes. This makes it easy to mix variables & text in a single string. The actual PHP term is __interpolation__. – Manngo May 01 '17 at 03:06
  • Thanks everyone for your help! I got it to work now. – Erin T. Aardvark May 01 '17 at 14:53

1 Answers1

0

You have errors in your $_POST you are using $ POST with space.

$field_name = $_POST['name'];
$field_address = $_POST ['address'];
$field_city = $_POST ['city'];

$field_homephone = $_POST ['homephone'];
$field_cellphone = $_POST ['cellphone'];
$field_email = $_POST ['email'];
$field_Room = $_POST ['Room'];

$field_checkindate = $_POST ['checkindate'];
$field_checkoutdate = $_POST ['checkoutdate'];
$field_comment = $_POST ['comment'];


$radio_button = $_POST['number'];
$drop_down_item = $_POST['state'];
Junius L
  • 15,881
  • 6
  • 52
  • 96