Page 1 of 1
First time using PHP
Posted: Sat Mar 03, 2018 11:22 am
by Lucious
I need to make a simple form that a user enters an amount and the forum multiplies the amount by 300
example
user enters the amount 23,000
they click submit and it gives them the answer 6,900,000
Any help or direction with this would be a great help
Re: First time using PHP
Posted: Wed Mar 07, 2018 6:57 pm
by Christopher
You can use PHP for that. The value would be from an HTML <input> field and PHP would receive it in the $_POST array.
File: form.php
Code: Select all
<?php
if (isset($_POST['number']) {
$number = filter_input(INPUT_POST, 'number', FILTER_SANITIZE_NUMBER_INT);
$total = $number * 300;
echo "$number x 300 = $total";
} else {
?>
<form action="form.php" method="post>
Number:<input type="text" name="number" value="" size="10">
<input type="submit" name="submit" value="Multiply">
</form>
<?php
}
?>
You could also do this in Javascript in the browser. Add an onSubmit event to the form and then get the value of the input field.