0

In this project I'm sending my html form to PHP. I use Xamp for the PHP side of things but I'm having issues with my PHP displaying after receiving information from the form. I've used the validator and the problem has to deal with <?PHP in my code. I've heard that you are suppose to include <?PHP outside of the but I'm not entirely sure. Not to mention, if you guys want me to include my html form to see if it helps I can do it anytime. Any veteran advice is very much appreciated. Thanks for the help!

<!DOCTYPE html>
<html lang="en">

<head>
  <!--Name: Michael Fields
        Filename: fields-group3-l13-lab-project-code.php
    Blackboard User Name: ddedominicis
    Class Section: CTI.110.0008
    Purpose:  Using the flowgorithm algorithm attached complete the missing statements of code
    -->
  <meta charset="utf-8" />
  <title>L13 Event Form </title>
    
    <style>
        body {
            color:blue;
            font-size:20px
        }
        
        h1 {
            color: navy;
        }
        ul {
            list-style-type:none;
            padding:0;
            border: solid green;
            color: navy;
        }
        li {
            padding: 1.5px;
            border: solid blue;
            color: navy;
        }
    </style>
    
</head>
<body>

<?php
//Using the flowgorithm algorithm transComplete logic, create the php code that follow the logic    

    //The $_POST superglobal takes the passed values from the html form input.  These values are then assigned a PHP variables name using the assignment statement.  the $_POST MUST match the name=xxx in the form input type
    $name = $_POST['name'];
    $phone = $_POST['phone'];
    $childTickets = $_POST['childTickets'];
    $adultTickets = $_POST['adultTickets'];
    $date = $_POST['date'];
    $subtotal = $_POST['subtotal'];
    $salesTax = $_POST['salesTax'];
    $fee = $_POST['fee'];
    $totalCost = $_POST['totalCost'];
                        
    /*TAX, MAXFee, MINFee, and ATTENDcompare are declared as constants. You can use the define function and the language construct const.*/
function transComplete($adultTickets, $childTickets, $date, $name, $phone) {
    const TAX = 0.07;
    const MAXfee = 1.00;
    const ATTENDcompare = 5;
    const MINfee = 0.5;
    const subtotal = 0;
    const salesTax = 0;
    const totalAttend = 0;
    const fee = 0;
    const totalCost = 0;
    if ($totalAttend <= $ATTENDcompare) {
        $fee = $totalAttend * $MAXfee;
    } else { 
        $fee = $totalAttend * $MINfee;
    }                       
    $subtotal = ($adultTickets * 35.00) + ($childTickets * 30.00);
    $salesTax = ($subtotal * TAX);
    $totalCost = ($subtotal + $salesTax + $fee);        
}
    //Print is also considered to be a function while echo is a language construct. Either will work for this course    
    print "<h1>Summary Ticket Cost for Concert</h1>";
    //The period (.) is a concatenation symbol. For Flowgorithm you used an (&) ampersand
    print ("<p>Thank you <b>".$name."</b> at <b>".$phone. "</b>.  Details of your total cost <b>$" .$totalCost. "</b> are shown below:</p>");
    print("<ul><li>Adult Tickets: $adultTickets. </li></ul>");
    print("<ul><li>Child Tickets:" .$childTickets. "</li></ul>");
    
    print("<ul><li>Date:</li></ul>");
            
    /*All languages have a way to format output.  The number_format function does this for numbers in PHP. We are asking for two decimal points since this is dollar data*/
    echo("<li>Sub-total: $".number_format($subtotal, 2)."</li>");
    print("<li>Sales tax: $"                  "</li>");
    print("<ul><li>Fee: $".number_format($fee, 2)."</li></ul>");
    echo("<ul><li><b>TOTAL:</b><b> $".number_format($totalCost, 2)."</b></li></ul>");
    print ('<br><a href="fields-l13-lab-project-form.html">Return to Main Page</a>');
    
?>
</body>
</html>
  • 1
    _"I'm having issues with my PHP displaying"_... do you mean you're seeing the PHP source code in your browser? What URL are you opening? – Phil Dec 03 '20 at 02:33
  • 1
    FYI PHP does not have a `const` keyword outside of a `class` context. See https://www.php.net/manual/language.oop5.constants.php – Phil Dec 03 '20 at 02:35
  • The file must have `.php` extension and it must be run through a web server. Just opening it in a browser will not work. – loa_in_ Dec 03 '20 at 02:36
  • If the validator in question is a HTML validator, you must feed it the results of your PHP script, not the script itself. The results can be found as the page source once you access the web page with the script. – loa_in_ Dec 03 '20 at 02:37
  • https://stackoverflow.com/a/5710680/7387397 – Sysix Dec 03 '20 at 02:44

0 Answers0