I am new to PHP and have just started learning it. I may have gotten in over my head. I am trying to have a user input a buy value and a sell value in an html form, and then have php perform mathematical operations on those values, and finally, output the value calculated by the math operations.
<html>
<head>
<title>PHP Test</title>
</head>
<body>
<form action="" method="post">
Buy Price: <input type="number" name="buyprice" value="<?php echo
$buyprice;?>">
Sell Price: <input type="number" name="sellprice" value="<?php echo
$sellprice;?>">
<input type="submit" name="submit" value="Calculate" />
</form>
<?PHP
$buyprice = $_POST['buyprice'];
$sellprice = $_POST['sellprice'];
$tax = 0.95;
$profit = 0;
if (isset($_POST['submit'])) { //to check if the form was submitted
$profit = (($sellprice * $tax) - $buyprice);
print $profit;
}
?>
</body>
</html>
This is my attempt at it, I would appreciate any tips or ideas on how to accomplish what I want to do. Basically, the user inputs two values into the form, the php needs to use those values as variables and perform mathematical operations with them, and then I need it to output the calculated value to the page. The calculation should not be performed until the user presses the calculate button.
I'm also curious if there is a way to prevent the user from adding numbers that are negative in value (min max?). I was also wondering if there was a way to remove the arrows from the input boxes in the form.
Thanks.
` for example. Most browsers will show it anyway, but it's not according to w3 standards.
– Mark Baijens Sep 07 '17 at 14:28