+234-811-999-6059, +234-706-062-4802 support@progmatech.com
Ok, I appreciate those that comment on our previous topic. it tells me some people are interested. I will advise you to follow the tutorial and practice it on your system.

“Practice makes Perfect”

No biddle-diddle, straight to the point. Let’s talk about the basic keywords we mentioned earlier. See: Day 1: Introduction to PHP/Mysql.

Assuming you have installed xampp and Dreamweaver. On windows, go to “C:xampphtdocs”. if you install it on another drive, check the drive, you will see xampp, open it you’ll see htdocs, open htdocs. Htdocs is like your hosting space online (i.e. public_html) where you keep your website files.

Example 1:We want to create a website to perform simple calculation using php.

Solution:
Create a folder inside htdocs, call it calculator. Open Dreamweaver, go to File > New (Ctrl + N), Select Dynamic Page, Under dynamic page choose PHP. New PHP page is created. Save it as index.php into calculator folder.

In Dreamweaver, at the top left part, you will see three buttons they are; CODE | SPLIT | DESIGN

Dreamweaver is a nice software. You can click DESIGN to design your HTML/CSS website without coding. Automatically Dreamweaver will create the code for you. To see the code, click CODE. SPLIT lets you see the CODE and the DESIGN view splitting the window into two for you.

Hope, you understand how dreamweavercode | split | design button works. Now to start writing our php code, click CODE button. You will see the following HTML code;
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>
<html xmlns=”http://www.w3.org/1999/xhtml“>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
You can change your title to something like Simple Calculator; like this  <title>Simple Calculator</title>

Write your code and other site content within the body tag i.e. <body> </body>

<body> </body>.
Ok, let’s solve our problem. What’s it again? “creating a website to perform a simple calculation using PHP“.

Now, this is where your creativity comes in. You need to think on how to achieve this. Different people can do this in
different ways and still achieve the same result.

#1 We need a form. One input box to accept first value from user, second box to accept second value from the same user, and a button to click. See the code below;
<form name=”frmname” action=”” method=”post”>
<input type=”number” required name=”num1″ placeholder=”Enter Your First Number” />
<input type=”number” required name=”num2″ placeholder=”Enter Your Second Number” />
<button name=”cmdsubmit”>Calculate</button>
</form>
Now, Place the code before form tag;
<?php
echo ‘<h2>Welcome to Simple Calculator</h2>’;
if(isset($_POST[“cmdsubmit”])){
if($_POST[“num1″] == ”){ echo ‘First number is required’; }
elseif($_POST[“num2″] == ”){ echo ‘Second number is required’; }
else{
$result = $_POST[“num1”] + $_POST[“num2”];
echo ‘Result is ‘.$result;
}
}
?>
Assuming you know HTML already, so no need to explain the form tags above. Let’s explain the PHP code above.

First line:  echo ‘<h2>Welcome to Simple Calculator</h2>’; Print out the content in single quote ‘’ on webpage. to print out simple on website from php, use echo follow by string.

Second line: this is if statement
if (condition){…..}
if cmdsubmit which is submit button is submitted perform the next state line. So, we use isset() which is another php keyword to check if form is submitted; isset($_POST[“cmdsubmit”])

Next statement line;
if($_POST[“num1″] == ”){ echo ‘First number is required’; }
elseif($_POST[“num2″] == ”){ echo ‘Second number is required’; }
else{
}
We validated the form, checking if num1 is not empty, and num2 is not empty. if they are empty echo. Else, i.e. if num1 and num2 is not empty, perform the code;
$result = $_POST[“num1”] + $_POST[“num2”];
echo ‘Result is ‘.$result;
The code above calculate the two numbers and store the value in $result. $result is a variable. In php, this is how to declare a variable. You can use any name but be careful, don’t use keyword as your variable. You can use something like this;
$r, or $rs, $result, $result_calc

Do not declare a variable like this; $result-calc. It totally wrong. If you do this the system will throw error.
And don’t forget, at the end of each statement line is a semi-colon (;) If you omit this also the system will throw error.

Later, we will talk about the declaration of Variable and Constant, PHP Syntax, Type of Error

Cheers!