Thursday, July 18, 2019

Positive and Negative Number Checker in PHP

Here is a sample program that will ask the user to give a number and then the program will check and determine if the given number is a positive and negative number.  Let us assume zero belongs to a positive number in this example.

I am currently accepting programming work, IT projects, school and application development, programming projects, thesis and capstone projects, IT consulting work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.

My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

Here in Bacolod I also accepting computer repair, networking and Arduino Project development at a very affordable price.

My personal website is http://www.jakerpomperada.com



Sample Program Output


Program Listing

index.php

<!DOCTYPE html>
<html lang="en">
<head>
<style>
body {
font-family: arial;
}
</style>
<?php
error_reporting(0);
$display="";
$val_num=$_POST['val_num'];
if(isset($_POST['clear'])){
$val_num="";   
$display="";
}
?>
<meta charset="UTF-8">
<title>Positive and Negative Number Checker Using PHP</title>
</head>
<body>
<h2>Positive and Negative Number Using PHP</h2>
<h4>Created By Mr. Jake R. Pomperada</h4>
<form action="" method="post">
<b>Give a Number</b><br/><br>
<input type="text" name="val_num" value="<?php echo $val_num; ?> "  required autofocus><br/><br>
<input type="submit" name="submit" value="Submit">  &nbsp;&nbsp;&nbsp;

<input type="submit" name="clear" value="Clear">
</form>
<br>
<?php

function phpAlert($msg) {
    echo '<script type="text/javascript">alert("' . $msg . '")</script>';
}

if(isset($_POST['submit'])){
$val_num=$_POST['val_num'];

if ( trim($val_num) == '' ) {
    
phpAlert(   "Cannot Be Empty."   );
}

if ($val_num >= 0) {
$display=" ";
echo $display;

$display = "The given nunber $val_num is a POSITIVE number.";
echo $display;
else {
$display =  "The given nunber $val_num is a NEGATIVE number.";
echo $display;
}
  

}
?>
</body>
</html>



No comments:

Post a Comment