Skip to content
Advertisement

How to make HTML heading use PHP variables in a PHP file

for a project I need to make a PHP file that gives back a reservation response and in the Heading of the response I need to have a Bold heading in big letters that says “Thank you John Smith for your Reservation”. I know I can use before the php code but when I do i cant get my variables to work.

Note: John Smith is just a example, I need the name to pop up as what someone enters from the field so basically a non-static heading.

Thank you for your time 😀

<?php
//config file
  require_once("file_exceptions.php");

  // create short variable names
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$state = $_POST['state'];
$outdate = $_POST['outdate'];
$indate = $_POST['indate'];
$numberofpeople = $_POST['numberofpeople'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$cardtype = $_POST['cardtype'];
$cardnum = $_POST['cardnum'];

  $DOCUMENT_ROOT = $_SERVER['DOCUMENT_ROOT'];
?>
<html>
<body>
<?php
//displays what the user put in the form by using the vairables


echo '<p>The following is the infomation you entered: </p>';

echo "Number and Street ".$address."<br />";
echo "City ".$city."<br />";
echo "ZipCode ".$zip."<br />";
echo "State ".$state."<br />";
echo "Check-In Date ".$indate."<br />";
echo "Check-Out Date ".$outdate."<br />";
echo "Number of People ".$numberofpeople."<br />";
echo "Phone ".$phone."<br />";
echo "Email ".$email."<br />";
echo "Card Type ".$cardtype."<br />";
echo "Card Number ".$cardnum."<br />";
?>
</body>
</html>

Advertisement

Answer

You can use it like that

<?php
//displays what the user put in the form by using the vairables
echo '<h1>Thank you '.$fname.' '.$lname.' for your Reservation</h1>';
echo '<p>The following is the infomation you entered: </p>';

I can suggest you – check how to trim input data. Because your code now is vulnerable. You can check this topic in SO – PHP need to trim all the $_POST variables

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement