|
[php home] Php_4: Using HTML Forms with PHP Variables (NUMBERS) You can use a similar process to pass numbers from an HTML form to PHP. You will need to create the HTML forms page and write the PHP code that will carry out the task. Create a page that will add two numbers together. Again, we could use any of the forms, but we will create two text boxes. Create your HTML page and save it as "addition.htm" <html> <form action="php_4.php" method="post"> <input type="submit"> </body> Create your PHP page and save as php_4.php. <?php echo $_POST['number2']; echo $total; Note: PHP uses the standard mathematic
operators. Formatting Numbers: Two frequently used PHP functions are "round()" and "number_format()" The "round()" function will let you round to the closest integer
(a number without decimal points) or to a specified number of decimal places The "number_format()" function displays a number in a more
frequently used format or to specify a certain number of decimal points Exercise 4.1: Item 1 cost: xxxxxxxx Use the following method on your PHP page- note how both HTML and PHP are used together. item 1 cost: $<?php echo $_POST['cost1']; ?><br> Make sure that you format your total so that is has two decimal points. |