【问题标题】:How to make HTML heading use PHP variables in a PHP file如何使 HTML 标题在 PHP 文件中使用 PHP 变量
【发布时间】:2020-10-15 03:08:54
【问题描述】:

对于一个项目,我需要创建一个 PHP 文件来返回预订响应,并且在响应的标题中我需要有一个大写的粗体标题,上面写着“感谢 John Smith 的预订”。我知道我可以在 php 代码之前使用,但是当我这样做时,我无法让我的变量工作。

注意:John Smith 只是一个示例,我需要弹出名称作为某人从该字段输入的内容,因此基本上是一个非静态标题。

感谢您的宝贵时间:D

<?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>

【问题讨论】:

    标签: php html css


    【解决方案1】:

    你可以这样使用它

    <?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>';
    

    我可以建议您 - 检查如何修剪输入数据。因为您的代码现在很容易受到攻击。 您可以在 SO - PHP need to trim all the $_POST variables

    中查看此主题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-25
      • 2014-06-04
      • 2015-09-21
      • 1970-01-01
      • 1970-01-01
      • 2011-07-25
      • 1970-01-01
      • 2016-09-13
      相关资源
      最近更新 更多