Play With Love Calculator in PHP

Introduction

In this article, I make a simple PHP "love calculator" application and in this process,  I am simply using a HTML design form to provide a look and feel for the user and also write a PHP script, that is responsible for calculating the love percentage of you and your lover or say with his/her person. Now I will start with the design phase.

Design Form

In this application I am taking two input HTML TextBoxes for entering your name and your lover's name, a button for the love calculation and an image slider with JavaScript code that rotates an image every 2 seconds.

Now I write the code here for the user interface; see:

<html>

<head>

<script type="text/javascript">

    var slideimages = new Array()

    function slideshowimages() {

        for (i = 0; i < slideshowimages.arguments.length; i++) {

            slideimages[i] = new Image()

            slideimages[i].src = slideshowimages.arguments[i]

        }

    }

</script>

</head>

<body>

<form action="calculate.php" method="post">

<table style="border:groove #00FF99">

<tr>

<td style="background-color:aqua">Enter your name</td>

<td rowspan="2" style="font-family:'Adobe Gothic Std';color:brown">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Love calculator<br />

<img src="dil.png" alt="Slideshow Image Script" title="Slideshow Image Script" name="slide" border=0 width=150 height=120>

<script type="text/javascript">

    slideshowimages("dil.png", "dil1.jpg", "dil3.jpg")

    var slideshowspeed = 2000

    var whichimage = 0

    function slideit() {

        if (!document.images)

            return

        document.images.slide.src = slideimages[whichimage].src

        if (whichimage < slideimages.length - 1)

            whichimage++

        else

            whichimage = 0

        setTimeout("slideit()", slideshowspeed)

    }

    slideit()

</script>

</td>

<td style="background-color:aqua">Enter your lovers name</td>

</tr>

<tr>

<td><input type="text" name="name" style="color:burlywood"/></td>

<td><input type="text" name="name1" style="color:burlywood"/></td>

</tr>

<tr>

<td>&nbsp;</td>

<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" name="submit" value="Calculate" style="color:brown"/></td>

<td>&nbsp;</td>

</tr>

<tr><td></td></tr>

</table>

</form>

</body>

</html>

Output

love-cal.gif

Now after doing the script above, I wrote a simple PHP script to get back the love percentage on behalf of the PHP rand() methods, instated of this method you can also use various types of methodologies to calculate the love percentage.


Now, I write the PHP code, that automatically chooses a random number using the rand function to assign you when you click on the calculate button.

<html>

<body>

<?php

static $staticvar=1;

$_POST['submit'];

if($_POST['name']!=NULL && $_POST['name1']!=NULL)

{

$ran = rand(20, 100);

 $staticvar++;

echo "<h2>Your love realtion is <b>". $ran ." </b>%</h2></br>";

echo "<a href=\"http://localhost:8090/lovecal.php\"><b><h1>Click Here for for Calculate with New one<h1></b></a>";

//echo "<a href=\"http://localhost:8090/lovecal.php\"><b><h1>Click Here for Calculate with New one</h1></b></a>";

}

else if($_POST['name']!=NULL )

{

echo "<b><h2>Please enter your name</h2></b></br>";

echo "<a href=\"http://localhost:8090/lovecal.php\"><b><h1>Click Here for ReEnter you and your lover names<h1></b></a>";

}

else if($_POST['name1']!=NULL )

{

echo "<h1></b>Please enter your lover name</h2></b></br>";

echo "<br\>";

echo "<a href=\"http://localhost:8090/lovecal.php\"><b><h1>Click Here for ReEnter you and your lover names<h1></b></a>";

}

else

{

echo "<h2><b>Please Enter names</h2></b></br>";

echo "<a href=\"http://localhost:8090/lovecal.php\"><b><h1>Click Here for ReEnter you and your lover names<h1></b></a>";

}

 

echo "</br>";

echo "</br>";

?>

</body>

</html>

Output

love-calculator-in-php.gif

Up Next
    Ebook Download
    View all
    Learn
    View all