Friday, 5 January 2018

Addition Of Two Numbers In PHP By Taking Input From User


Step 1: 

Start the XAMPP server
Click on the "Start" button next to "Apache" to start your Apache Web server and also start "MySQL"

Step 2:Create demo.html

<html>
<body>
<form method="post" action="add.php">
Enter First Number:
<input type="number" name="num1" /><br>
Enter Second Number:
<input type="number" name="num2" /><br>
<input  type="submit" name="submit" value="Add">
</form>
</body>
</html>

Step 3: Create add.php

<?php
    if(isset($_POST['submit']))
    {
        $number1 = $_POST['num1'];
        $number2 = $_POST['num2'];
        $sum =  $number1+$number2;   
echo "The sum of $number1 and $number2 is: ".$sum; 
}
?>

Step 4:

Save it on htdocs folder under xampp server in c: drive. The file path is "C:\xampp\htdocs" for your Web server

Step 5:Run the application

Open the browser (chrome) and type it
localhost/demo.html

OR

Step 1:  Save it as add.php
<html>
<body>
<form method="post">
Enter First Number:
<input type="number" name="num1" /><br><br>
Enter Second Number:
<input type="number" name="num2" /><br><br>
<input  type="submit" name="submit" value="Add">
</form>

<?php
    if(isset($_POST['submit']))
    {
        $number1 = $_POST['num1'];
        $number2 = $_POST['num2'];
        $sum =  $number1+$number2;   
echo "The sum of $number1 and $number2 is: ".$sum; 
}
?>

</body>
</html>

Step 2: Run the application

Open the browser (chrome) and type it
localhost/add.php

Note: 
If you want to display output in same page then use this method and you know that php can embedded with html and css

No comments:

Post a Comment

apply function in R

1) apply function: It takes 3 arguments matrix,margin and function.. Example: m<-matrix(c(1,2,3,4),nrow=2,ncol=2) m #1 indicates it is ap...