Brocktoon Brocktoon - 1 month ago 8
PHP Question

Fatal error: Function name must be a string in C:\xampp\htdocs\display_discount.php on line 13

I'm learning PHP this semester and I'm both enjoying it and immediately lost a bit on my first real assignment. There are a few other similar questions but, because I'm new, I'm not able to extrapolate their answers to help with this.

I am getting the error in the title. The mission is to create POST code to handle all of the product description, price data, etc. I've added that code, but I'm getting the must be a string error on like 13 (under product description) but am unsure why.

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

Answer

$_POST is not a function but an array. Functions are invoked with parameters between parentheses, arrays are queried with square brackets. Thus:

 $_POST('product_desc')

should be:

 $_POST['product_desc']