First time using PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Lucious
Forum Newbie
Posts: 1
Joined: Sat Mar 03, 2018 11:18 am

First time using PHP

Post 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
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: First time using PHP

Post 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.
(#10850)
Post Reply