PHP Program to check if a Number is Postive or Negative

To check if a number is positive or negative in PHP using an HTML form, you can create a simple web page that takes input from the user through a form and then processes that input in PHP. Here’s an example of how you can do this:

  1. Create an HTML form (index.html):
  2. Create a PHP script (check_number.php) to process the form input and check if the number is positive or negative:

Here’s how this works:

  • The index.html file contains a form with an input field where the user can enter a number. When the user submits the form, it sends the input to the check_number.php script for processing.
  • In check_number.php, we check if the request method is POST, which indicates that the form has been submitted. We retrieve the user input using $_POST["number"].
  • We then use PHP to check if the number is positive, negative, or zero, and store the result in the $result variable.
  • Finally, we display the result on the web page along with a link to go back to the input form.

To use this code, save the HTML code in an index.html file and the PHP code in a check_number.php file in the same directory. Open the index.html file in your web browser, enter a number in the form, and click “Check” to see the result.

Related Posts

Leave a Reply