-1

I'm still stuck on this PHP code. I'm trying to code it where the user inputs some information and the PHP code displays the information the user inputted it. Basically I'm trying to build a confirmation page so the user sees the information inputted before submitted it.

HTML

<DOCTYPE html>
<html>
 <head>
  <meta charset="UTF-8">
  <title>DormAngel Booking Form</title>
 </head>
 <body>
  <form action="welcome.php" method="POST">
   <fieldset>
    <legend> Personal Details: </legend>
     <label for="fname>"></label>
      <input type="text" name="Name" id="fname" required autofocus placeholder="First Name" pattern="[a-zA-Z]{3,}" title="Please enter more than three letters">
     <label for="lname>"></label>
      <input type="text" name="Last Name" id="lname" required autofocus placeholder="Last Name" pattern="[a-zA-Z]{3,}" title="Please enter more than three letters">
     <label for="email">Email: </label>
      <input type="text" name="email" id="email" required placeholder="Your school email" pattern="[a-zA-Z]{3,}@[a-zA-Z]{3,}[.]{1}[a-zA-Z{2} title="Please enter a valid email address>
     <label for="phone">Phone: </label>
      <input type="tel" name="phone" id="phone" required placeholder="Please enter in your phone number">
    <select name="country" required>
     <option value=""> </option> 
     <option value="US">US</option>
     <option value="UK">UK</option>
     <option value="AUS">AUS</option>
    </select>
   </fieldset>
   <br>
   <fieldset>
    <legend> Booking Details: </legend>
    <input type="date" name="date" min="2018-10-07" max="2018-10-31">
    <input type=time min=9:00 max=17:00 step=900> 
    <br>
    <br>
    <label for="dorm">Dormitory: </label>
    <br>
    <select name="dorm" required>Dormitory
     <option value="Cypress">Cypress Hall</option>
    </select>
    <br>
    <br>
    <label for="floor">Floor: </label>
    <br>
    <select name="floor" required>Floor: 
     <option value=""></option>
     <option value="02">02</option>
     <option value="03">03</option>
     <option value="04">04</option>
     <option value="05">05</option>
     <option value="06">06</option>
     <option value="07">07</option>
     <option value="08">08</option>
    </select>
    <br>
    <br>
    <label for="roomnumber">Room Number: </label>
    <br>
    <select name="roomnumber">Room Number: 
     <option value=""></option>
     <option value="22">22</option>
    </select>
    <br>
    <br>
    <label for="roomletter">Room Letter: </label>
    <br>
    <select name="roomletter" required="">Room Letter
     <option value=""></option>
     <option value="A">A</option>
     <option value="B"> B</option>
    </select>
    <button type="submit">Submit</button>
   </fieldset>
  </form>    
 </body>
</html>

PHP

<html>
<head>
<title>Confirmation Page of Web Form</title>
</head>
<h1>Confirmation Page of Customer Info</h1>

<p>Thank you for submitting this form.</p>

<p>We have successfully received it.</p>

<p>Below is a summary of the information you provided.<br><br>  
<?php
echo 'First Name: ' . $_POST ["Name"] . '<br>';
echo 'Last Name: ' . $_POST ["Last Name"] . '<br>';
echo 'Email Address: ' . $_POST ["email"] . '<br>';
echo 'Telephone Number: ' . $_POST ["phone"];
?>
</p>
</html>

What is wrong with my code?

Angel
  • 83
  • 1
  • 9
  • 1
    Can you tell me what error you getting? – Kalpesh Shende Oct 13 '18 at 21:04
  • @KalpeshShende Confirmation Page of Web Form

    Confirmation Page of Customer Info

    Thank you for submitting this form.

    We have successfully received it.

    Below is a summary of the information you provided.

    '; echo 'Last Name: ' . $_POST ["Last Name"] . '
    '; echo 'Email Address: ' . $_POST ["email"] . '
    '; echo 'Telephone Number: ' . $_POST ["phone"]; ?>

    – Angel Oct 13 '18 at 21:06
  • That is the error I'm getting. – Angel Oct 13 '18 at 21:06
  • 1
    That is not an error my friend, it seems like your page is not being interpreted by the browser.. What is the name of the file with the php code? Is it welcome.php? Also are you running a server or you just opening the files in browser? – Mohammad C Oct 13 '18 at 21:12
  • @noyanc The page is welcome.php and I'm opening it from the browser. – Angel Oct 13 '18 at 21:32
  • by the way, your code is very bad practice from a security point of view. You do not sanitize any POST fields and are vulnerable for possible XSS and common scripting attacks. – Doğan Uçar Oct 13 '18 at 21:50
  • @dogano this very is for practice purposes using HTML and PHP. I'm not trying to build a secure application. – Angel Oct 13 '18 at 21:56

2 Answers2

-1

You have forgotten the <body> tag in your html.

Kubwimana Adrien
  • 2,463
  • 2
  • 8
  • 11
  • Hey everyone, I found the answer. Everything in my code was correct, however I wasn't running a PHP server in the background which is why it was displaying the entire PHP code. I used MAMP and it worked! Thank you everyone who helped contribute. – Angel Oct 14 '18 at 00:43
-1

Replace the code to be this way.

        <html>
    <head>
    <title>Confirmation Page of Web Form</title>
    </head>
    <h1>Confirmation Page of Customer Info</h1>

    <p>Thank you for submitting this form.</p>

    <p>We have successfully received it.</p>

    <p>Below is a summary of the information you provided.<br><br>  
    <?php
    echo 'First Name: ' . $_POST["Name"] . '<br>';
    echo 'Last Name: ' . $_POST["Last Name"] . '<br>';
    echo 'Email Address: ' . $_POST["email"] . '<br>';
    echo 'Telephone Number: ' . $_POST["phone"];
    ?>
    </p>
    </html>