Wednesday, June 26, 2013

php simple programs - 1st degree equation solver

php simple programs
In this lesson we will take a php simple program which can be used to solve 1st degree equations based on what we have learned so far,Let's go
This is the whole code

<style type="text/css">
#e1 {
border:medium;
float:center;
background-color:#0C3;
border-radius:10px;

}
#sol {
background-color:#999;
float:center;
border-radius:10px;
margin:250px;
margin-top:5px;
}



</style>


<div id="e1">
<center>
<h1>this program solve 1sd degree equations ax+b=0</h1>
<form action="2ndequation.php" method="post" >
 a= <input name="n1" type="number" />
 b= <input name="n2" type="number" />
<input name="submit" type="submit" value="calculate"  />
 </form>
 </center>
 </div>
 <div id="sol">
 <center>
 <?php
if(isset($_POST['submit'])){
$a=$_POST['n1'];
$b=$_POST['n2'];
if($a==0 && $b==0){
echo "the variable have infinite values";
}else if($a==0){
echo "no solutions";
}else{
$x=(-$b/$a);
echo "the solution of equation is x="."$x";
}

}
?>
</center>
</div>

The result will be like this:

php simple programs


Now let's explain it
From <style type="text/css"> To </style> is a CSS code if you want a section about CSS just leave a comment below
Just after it we define a block and give it an ID if you want a section about HTML just leave a comment below

We put <center> to place the block in the middle of the page
We add a title and define a form which will be used to input the values of parameters a and b and a submit buton and after it we close the block

we start a new block and put in it the php code
we use an condition to verify if the buton are pressed with isset function, so if the buton pressed it will do the code between brackets with the red color

We define two variables a and b they will receive the values from the form with POST function
The rest of the code is a math logic conditions I think it's easy to understand however if you find any probleme just leave me a comment and I will help you OK

I hope you enjoy and understand the php simple programs lesson, if you like it share it with your freind
See you next time.

Share This!



No comments :

Post a Comment