Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,150,847 members, 7,810,264 topics. Date: Saturday, 27 April 2024 at 03:30 AM

How To Create Calculator Using Php And Html Script Www.niyimarc.org.ng - Webmasters - Nairaland

Nairaland Forum / Science/Technology / Webmasters / How To Create Calculator Using Php And Html Script Www.niyimarc.org.ng (312 Views)

⭐⭐⭐⭐⭐ Youwin.org.ng Domain Name Is Now For Sale. Grab it! / Let's Build A Loan Calculator Using Pure Javascript 2019 / Creating A Simple Calculator Using HTML,CSS And Javascript (2) (3) (4)

(1) (Reply)

How To Create Calculator Using Php And Html Script Www.niyimarc.org.ng by niyimarc(m): 2:45am On Sep 12, 2018
I know building a calculator is something fun to play with as a beginner learning PHP, it’s something good to work with so as to develop ourselves on PHP. Am actually sharing this with my friends who are lovers of PHP. Follow the below steps to design the calculator;

You are free to copy the code below to use on your work.

STEP 1: Create a new PHP file, with “.php” extension Eg; “index.php”. Set up your HTML document on the new .php file you created.
[center] <!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

</body>
</html>[/center]

STEP 2: Create a “<form>” tag between your “<body>” tag, then use the “<input>” twice tag to determine the first and second field to input your number on the browser.

[center]<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

<form>
<input type="number" name="num1" placeholder="0"><br><br>
<input type="number" name="num2" placeholder="0"><br><br>
</form>

</body>
</html>[/center]

You can save the file and refresh the browser to see the result you have so far.

Step 3; Use the “<select>” tag immediately after the end of the input tag below to list the operator options. We are using this tag if you want to add, subtract, multiply or divide.


[center]<select name="operator">
<option>None</option>
<option>+</option>
<option>-</option>
<option>*</option>
<option>/</option>
</select><br><br>[/center]

Note that we are to define the name of the “<select>” tag. In our case, the name for the “<select>” tag is “operator”

Step 4; The next thing we need to do is to include the button to calculate our work.

[center]<button name="submit" type="submit" value="submit">Calculate</button>
<br>[/center]

Note that when we click on the submit button on the browser, the information input in the text field will be added to the url of the page.

Step 5; We are going to use the “$_GET” to get the information in the url by using PHP. Put the below code immediately after the “<form>’ tag.


[center]<?php
if (isset($_GET['submit'])) {
$result1 = $_GET['num1'];
$result2 = $_GET['num2'];
$operator = $_GET['operator'];

}

?>[/center]


Step 6; Lets determine how our operator will will work. we will be using “switch” you can also use the “if” statement to do this if you like.

[center]<?php
if (isset($_GET['submit'])) {
$result1 = $_GET['num1'];
$result2 = $_GET['num2'];
$operator = $_GET['operator'];

switch ($operator) {
case 'None':
echo "you must select a method";
break;
​[/center]

To get the full code in one file, visit my website: https://niyimarc.org.ng/2018/09/06/build-a-simple-calculator-with-php/

(1) (Reply)

Who Knows About picture archiving and communications system (PACS) / How To Create An Ebook And Make Money From It / Nigerian Adsense Account For Sale #10k

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 11
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.