Search code examples
htmlphppercentagediscount

Discounts with PHP


I keep getting this error:

Fatal error: Unsupported operand types on line 34

And I'm not sure how to fix it, i am trying to make it so that the number that is entered into the form such as 10, will be the discount and it will echo the discounted price, can anyone help me fix this, here is the code

<!DOCTYPE html>
<html>
<head>
<title> Car Shop Cars! </title>
<link rel="stylesheet" type="css/text" href="style.css" 
</head>

<body>

<div id="header"> 
</div>

<div id="carpic">
</div>

<div id="price">
<center> This is the Nissan 350z and costs 8,999,999 <br>
please enter your promo code </center>
</div>

<div id="form">
<form action="index.php" method="post">

   <center> <input type="text" name="percent" id="percent" />
  <input type="submit"  /> </center>

</form> 
<?php
        $percent=$_POST['percent'];
    $total=['8,999,999'];

    /*calculation for discounted price */ 

    $discount_value= ($total / 100) *$percent;

    $final_price = $total - $discount_value;

    echo $final_price;

?> 
</div>

</body> 
</html>

Solution

  • This is invalid

    $total=['8,999,999'];
    

    I guess you mean something like this

    $total = 8999999;