doutangqi4444 2017-01-12 23:14
浏览 25
已采纳

如何显示产品描述(名称)?

so I am trying to get some PHP code working and the code is according to the book. But, when I calculate the discount on this program, the calculations are fine but the name doesn't appear.This is mind boggling because everything is exactly how it is in the book...

Can I get a second set of eyes to help me out on this? I'll provide some images and my code.

This is before everything is calculated: This is before everything is calculated

This is after everything is calculated ("Guitar" is supposed to appear next to product description):

This is after everything is calculated

This code is the HTML template before everything is calculated:

<!DOCTYPE html>
<html>

<head>
    <title> Product Discount Calculator</title>
    <link rel="stylesheet" type="text/css" href="main.css">
</head>

<body>
    <main>
        <h1>Product Discount Calculator (Complete)</h1>
        <form action="display_discount.php" method="post">
            <div id="data">
                <label>Product Description</label>
                <input type="text" name="product_description"><br>

                <label>List Price</label>
                <input type="text" name="list_price"><br>

                <label>Discount Percent:</label>
                <input type="text" name="discount_percent"><span>%</span><br>
            </div>

            <div id="buttons">
                <label>&nbsp;</label>
                <input type="submit" value="Calculate Discount"><br>
        </form>
    </main>
</body>
</html>

This code displays the discount and everything after it has been calculated:

<?php
    //get data from the form
    $product_description = filter_input(INPUT_POST, 'product _description');
    $list_price = filter_input(INPUT_POST, 'list_price');
    $discount_percent = filter_input(INPUT_POST, 'discount_percent');

    //Calculate the discount 
    $discount = $list_price * $discount_percent * .01;
    $discount_price = $list_price - $discount;

    //apply currency formatting to the dollar and percent amounts
    $list_price_f = "$".number_format($list_price, 2);
    $discount_percent_f = $discount_percent."%";
    $discount_f = "$".number_format($discount, 2); 
    $discount_price_f = "$".number_format($discount_price, 2);

?>

<!DOCTYPE html>
<html>

<head>
    <title> Product Discount Calculator (Complete)</title>
    <link rel="stylesheet" type="text/css" href="main.css">
</head>

<body>
    <main>
        <h1> Product Discount Calculator</h1>
                <label>Product Description:</label>
                <span><?php echo htmlspecialchars($product_description); ?></span>
                <br>

                <label>List Price:</label>
                <span><?php echo htmlspecialchars($list_price_f); ?></span><br>

                <label>Standard Discount:</label>
                <span><?php echo htmlspecialchars($discount_percent_f); ?></span><br>

                <label>Discount Amount:</label>
               <span><?php echo $discount_f; ?></span><br>

                <label>Discount Price:</label>
                <span><?php echo $discount_price_f; ?></span><br>
    </main>
</body>
</html>
  • 写回答

1条回答 默认 最新

  • dongnang8192 2017-01-12 23:20
    关注

    that can't be the whole code: The post results are not fetched anywhere

    There has to be a line $product_description = $_POST['product_description']; before the second part somewhere, to get the value from the product_description input field into the variable.

    ADDITION AFTER ADDED CODE IN QUESTION:

    You got an additional (wrong) space in there:

    $product_description = filter_input(INPUT_POST, 'product _description');
    

    remove it:

    $product_description = filter_input(INPUT_POST, 'product_description');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题