Showing posts with label Perimeter and Area of a Square Solver in PHP. Show all posts
Showing posts with label Perimeter and Area of a Square Solver in PHP. Show all posts

Tuesday, April 7, 2015

Perimeter and Area of a Square Solver in PHP


A simple program that I wrote in PHP to solve the perimeter and area of a square by providing the value of the side of the square by the user. 


If you have some questions please send me an email at jakerpomperada@yahoo.com and jakerpomperada@gmail.com. People here in the Philippines who wish to contact me can reach me at my mobile number 09173084360





Sample Program Output



Program Listing


<html>
<title> Perimeter and Area of a Square Solver </title>
<style>
body { 
  font-size:20px; 
  font-family:arial;
  color:blue;
  } 
</style>
<?php
error_reporting(0);

$values = $_POST['value'];

 // functions to find the perimeter and area of a square

 function perimeter_solve($variable) {
           return($variable * 4);
}

 function area_solve($variable) {
           return($variable * $variable);
}


if(isset($_POST['check'])) {

     if (ctype_alpha($values)) {
      echo "<script>";  
  echo "alert('PLEASE ENTER A NUMERIC VALUE.');";
  echo "</script>";
  $values="";
 }
 
else if(preg_match('#[^a-zA-Z0-9]#', $values)) {
      echo "<script>";  
  echo "alert('PLEASE ENTER A NUMERIC VALUE.');";
  echo "</script>";
        $values="";
      
}

    else  if ($values=="") {
      echo "<script>";  
  echo "alert('It Cannot Be Empty!!! Please enter a integer value.');";
  echo "</script>";
  $values="";
           }
else { 
      $title = "The value of the side of the square is ".$values." the equivalent in perimeter is " 
          .perimeter_solve($values)." . <br>";
$title .= "The value of the side of the square is  ".$values." the equivalent in area is" 
          .area_solve($values).".";
      
       }  
   }  

if(isset($_POST['clear'])) {
  $values=" "; 
  $title=" ";
  
}

?>
<body style='background-color:lightgreen'>
<div style='width:800px;margin:auto'>
  <br> <h1 align="center"> Perimeter and Area of a Square Solver</h2>
  <br>
<form action="" method="post">
 Enter the side value : <input type="text" name="value"    value="<?php echo $values; ?>" autofocus  size=20/>
   <input type="submit" name="check" value="Compute" 
  title="Click here to compute the perimeter and area of the square."/>
  <input type="submit" name="clear" value="Clear" 
  title="Click here to clear text box and values on the screen"/>
</form>
<br> 
<?php 
echo $title;
 ?>
  </body>
</html>