We will use a rand() function to generate a random value to show the love result. We will also use input box and anchor to collect the name of partners who wants to calculate their love.
To make the script easier, we will divide this script in 2 parts. First one is main part and second one is calculating part. In main part we will set two input box and an anchor to collect partners name, and in calculate part we will check that the input fields are empty or not, and the input fields are not empty, it will show the love percentage.
As we are creating a mobile site in wml, so the content-type will be text/vnd.wap.wml and we will use utf-8 encoding and xml version 1.0. So, at the top of the script at first we will writ
CODE
<?php
header("Content-type: text/vnd.wap.wml");
header("Cache-Control: no-store, no-cache, must-revalidate");
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"". " \"http://www.wapforum.org/DTD/wml_1.1.xml\">";
?>
<wml>
header("Content-type: text/vnd.wap.wml");
header("Cache-Control: no-store, no-cache, must-revalidate");
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"". " \"http://www.wapforum.org/DTD/wml_1.1.xml\">";
?>
<wml>
Now we will start the first part of our script. In this part we will set only 2 input box and an anchor.
CODE
echo "Your Name<br/> <input type=\"text\" name=\"uname\" format=\"text\" size=\"20\" value=\"$uname\"/>";
echo "<br/>Partner Name<br/> <input type=\"text\" name=\"pname\" format=\"text\" size=\"20\" value=\"$pname\"/><anchor>";
echo "<br/>[Calculate]";
echo "<go href=\"?action=calculate\" method=\"post\">";
echo "<postfield name=\"uname\" value=\"$(uname)\"/>";
echo "<postfield name=\"pname\" value=\"$(pname)\"/>";
echo "</go>";
echo "</anchor><br/>";
echo "<br/>Partner Name<br/> <input type=\"text\" name=\"pname\" format=\"text\" size=\"20\" value=\"$pname\"/><anchor>";
echo "<br/>[Calculate]";
echo "<go href=\"?action=calculate\" method=\"post\">";
echo "<postfield name=\"uname\" value=\"$(uname)\"/>";
echo "<postfield name=\"pname\" value=\"$(pname)\"/>";
echo "</go>";
echo "</anchor><br/>";
In our script, every part will be starts with this code
CODE
if($action=="part_name"){
echo "<card id=\"main\" title=\"alaponBD.com\">";
echo "<p align=\"center\">";
echo "<card id=\"main\" title=\"alaponBD.com\">";
echo "<p align=\"center\">";
And every part will be end with
CODE
echo "</p></card>";
}
}
And as we are using $action as, $uname and $pname, so we will put this code before starting the parts.
CODE
$action = $_GET["action"];
$uname = $_POST["uname"];
$pname = $_POST["pname"];
$uname = $_POST["uname"];
$pname = $_POST["pname"];
So, the codes will be
CODE
<?php
$action = $_GET["action"];
$uname = $_POST["uname"];
$pname = $_POST["pname"];
//////////////// Starting first part /////////////////
if($action=="main"){
echo "<card id=\"main\" title=\"alaponBD.com\">";
echo "<p align=\"center\">";
echo "<b>Love Calculator</b><br/><br/>";
echo "Your Name<br/> <input type=\"text\" name=\"uname\" format=\"text\" size=\"20\" value=\"$uname\"/>";
echo "<br/>Partner Name<br/> <input type=\"text\" name=\"pname\" format=\"text\" size=\"20\" value=\"$pname\"/><anchor>";
echo "<br/>[Calculate]";
echo "<go href=\"?action=calculate\" method=\"post\">";
echo "<postfield name=\"uname\" value=\"$(uname)\"/>";
echo "<postfield name=\"pname\" value=\"$(pname)\"/>";
echo "</go>";
echo "</anchor><br/>";
echo "</p></card>";
}
$action = $_GET["action"];
$uname = $_POST["uname"];
$pname = $_POST["pname"];
//////////////// Starting first part /////////////////
if($action=="main"){
echo "<card id=\"main\" title=\"alaponBD.com\">";
echo "<p align=\"center\">";
echo "<b>Love Calculator</b><br/><br/>";
echo "Your Name<br/> <input type=\"text\" name=\"uname\" format=\"text\" size=\"20\" value=\"$uname\"/>";
echo "<br/>Partner Name<br/> <input type=\"text\" name=\"pname\" format=\"text\" size=\"20\" value=\"$pname\"/><anchor>";
echo "<br/>[Calculate]";
echo "<go href=\"?action=calculate\" method=\"post\">";
echo "<postfield name=\"uname\" value=\"$(uname)\"/>";
echo "<postfield name=\"pname\" value=\"$(pname)\"/>";
echo "</go>";
echo "</anchor><br/>";
echo "</p></card>";
}
As we will continue our script, so we will not use
CODE
?>
here.
In second section we will add
CODE
if($uname==""){
echo "Please write your name<br/>";
echo "<br/><br/><a href=\"?action=main\">";
echo "[Back]</a><br/>";
}
echo "Please write your name<br/>";
echo "<br/><br/><a href=\"?action=main\">";
echo "[Back]</a><br/>";
}
and
CODE
else if($pname==""){
echo "Please write your partner name<br/>";
echo "<br/><br/><a href=\"?action=main\">";
echo "[Back]</a><br/>";
}
echo "Please write your partner name<br/>";
echo "<br/><br/><a href=\"?action=main\">";
echo "[Back]</a><br/>";
}
to check that the name box are properly filled or not.
And we will use
CODE
else{
$rn = mt_rand(1,100);
echo "Your love percentage at this moment is <b>$rn</b>%<br/>";
echo "<a href=\"?action=main\">";
echo "[Calculate another]</a><br/>";
}
$rn = mt_rand(1,100);
echo "Your love percentage at this moment is <b>$rn</b>%<br/>";
echo "<a href=\"?action=main\">";
echo "[Calculate another]</a><br/>";
}
to display the result.
So, the total script will look like this
CODE
<?php
header("Content-type: text/vnd.wap.wml");
header("Cache-Control: no-store, no-cache, must-revalidate");
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"". " \"http://www.wapforum.org/DTD/wml_1.1.xml\">";
?>
<wml>
<?php
$action = $_GET["action"];
$uname = $_POST["uname"];
$pname = $_POST["pname"];
//////////////// Starting first part /////////////////
if($action=="main"){
echo "<card id=\"main\" title=\"alaponBD.com\">";
echo "<p align=\"center\">";
echo "<b>Love Calculator</b><br/><br/>";
echo "Your Name<br/> <input type=\"text\" name=\"uname\" format=\"text\" size=\"20\" value=\"$uname\"/>";
echo "<br/>Partner Name<br/> <input type=\"text\" name=\"pname\" format=\"text\" size=\"20\" value=\"$pname\"/><anchor>";
echo "<br/>[Calculate]";
echo "<go href=\"?action=calculate\" method=\"post\">";
echo "<postfield name=\"uname\" value=\"$(uname)\"/>";
echo "<postfield name=\"pname\" value=\"$(pname)\"/>";
echo "</go>";
echo "</anchor><br/>";
echo "</p></card>";
}
///////////////////Starting second part
else if($action=="calculate"){
echo "<card id=\"main\" title=\"alaponBD.com\">";
echo "<p align=\"center\">";
echo "<b>Love Calculater</b><br/><br/>";
if($uname==""){
echo "Please write your name<br/>";
echo "<br/><br/><a href=\"?action=main\">";
echo "[Back]</a><br/>";
}
else if($pname==""){
echo "Please write your partner name<br/>";
echo "<br/><br/><a href=\"?action=main\">";
echo "[Back]</a><br/>";
}else{
$rn = mt_rand(1,100);
echo "Your love percentage at this moment is <b>$rn</b>%<br/>";
echo "<a href=\"?action=main\">";
echo "[Calculate another]</a><br/>";
}
echo "</p>";
echo "</card>";
}else{
echo "<card id=\"main\" title=\"alaponBD.com\">";
echo "<p align=\"center\">";
echo "<b>Love Calculater</b><br/><br/>";
echo "<a href=\"?action=main\">";
echo "[Start]</a><br/>";
echo "</p>";
echo "</card>";
}
?>
</wml>
header("Content-type: text/vnd.wap.wml");
header("Cache-Control: no-store, no-cache, must-revalidate");
print "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
echo "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"". " \"http://www.wapforum.org/DTD/wml_1.1.xml\">";
?>
<wml>
<?php
$action = $_GET["action"];
$uname = $_POST["uname"];
$pname = $_POST["pname"];
//////////////// Starting first part /////////////////
if($action=="main"){
echo "<card id=\"main\" title=\"alaponBD.com\">";
echo "<p align=\"center\">";
echo "<b>Love Calculator</b><br/><br/>";
echo "Your Name<br/> <input type=\"text\" name=\"uname\" format=\"text\" size=\"20\" value=\"$uname\"/>";
echo "<br/>Partner Name<br/> <input type=\"text\" name=\"pname\" format=\"text\" size=\"20\" value=\"$pname\"/><anchor>";
echo "<br/>[Calculate]";
echo "<go href=\"?action=calculate\" method=\"post\">";
echo "<postfield name=\"uname\" value=\"$(uname)\"/>";
echo "<postfield name=\"pname\" value=\"$(pname)\"/>";
echo "</go>";
echo "</anchor><br/>";
echo "</p></card>";
}
///////////////////Starting second part
else if($action=="calculate"){
echo "<card id=\"main\" title=\"alaponBD.com\">";
echo "<p align=\"center\">";
echo "<b>Love Calculater</b><br/><br/>";
if($uname==""){
echo "Please write your name<br/>";
echo "<br/><br/><a href=\"?action=main\">";
echo "[Back]</a><br/>";
}
else if($pname==""){
echo "Please write your partner name<br/>";
echo "<br/><br/><a href=\"?action=main\">";
echo "[Back]</a><br/>";
}else{
$rn = mt_rand(1,100);
echo "Your love percentage at this moment is <b>$rn</b>%<br/>";
echo "<a href=\"?action=main\">";
echo "[Calculate another]</a><br/>";
}
echo "</p>";
echo "</card>";
}else{
echo "<card id=\"main\" title=\"alaponBD.com\">";
echo "<p align=\"center\">";
echo "<b>Love Calculater</b><br/><br/>";
echo "<a href=\"?action=main\">";
echo "[Start]</a><br/>";
echo "</p>";
echo "</card>";
}
?>
</wml>
I have checked the script and found no bug or error. But if any one fiend any error, please inform so that I can correct the error. I think this tutorial will help beginner level PHP programmer.

