致命错误:函数名称必须是C:examplephtdocsdisplay_discount.php中第13行的


Fatal error: Function name must be a string in C:xampphtdocsdisplay_discount.php on line 13

这学期我在学习PHP,我很享受它,但在第一次真正的作业中立即失去了一些东西。还有其他一些类似的问题,但由于我是新手,我无法推断他们的答案来帮助解决这个问题。

我在标题上弄错了。任务是创建POST代码来处理所有的产品描述、价格数据等。我已经添加了该代码,但我在13(在产品描述下)上得到了一个字符串错误,但不确定原因。

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Product Discount Calculator</title>
    <link rel="stylesheet" type="text/css" href="main.css" />
</head>
<body>
    <div id="content">
        <h1>This page is under construction</h1>
        <label>Product Description:</label>
        <span><?php echo $product_description = $_POST('product_desc'); ?></span><br /> (THIS IS LINE 13)
        <label>List Price:</label>
        <span><?php echo $list_price_formatted = $_POST('list_price'); ?></span><br />
        <label>Standard Discount:</label>
        <span><?php echo $discount_percent_formatted = $_POST('std_discount'); ?></span><br />
        <label>Discount Amount:</label>
        <span><?php echo $discount_formatted= $_POST('discount_amt'); ?></span><br />
        <label>Discount Price:</label>
        <span><?php echo $discount_price_formatted = $_POST('final_price'); ?></span><br />
        <p>&nbsp;</p>
    </div>
</body>
</html>

$_POST不是一个函数,而是一个数组。函数是用括号之间的参数调用的,数组是用方括号查询的。因此:

 $_POST('product_desc')

应该是:

 $_POST['product_desc']

使用$_POST[...]而不是$_POST(...)