Site icon T4Tutorials.com

Addition of Real and Imaginary numbers in PHP MySQL

Addition of Real and Imaginary numbers in PHP MySQL

In this tutorial, we will cover the following programs;

  1. Addition of Real and Imaginary numbers
  2. Addition of Real and Imaginary numbers with form values entered by the user
  3. Addition of Real and Imaginary numbers with a database

Addition of Real and Imaginary numbers

<html>
<body>
<?php
$real1=9;
$imag1=2;
$real2=4;
$imag2=12;
$sum1=$real1 + $real2;
$sum2=$imag1 + $imag2;
echo"<h2>addition of complex number is $sum1+$sum2";
echo "i";
?>
</body>
</html>

Addition of Real and Imaginary numbers with form values entered by the user

<html>
<body>
<h1>Assigment 3</h1>
<h2>Addition of Real and Imaginary</h2>
<form method="post">
type 1st real number<br><input type="text" name="real1"><br>
<br>
type 1st umaginary number<br><input type="text" name="imag1">
<br><br>
type 2nd real number<br><input type="text" name="real2"><br>
<br>
type 2nd imaginary number<br><input type="text" name="imag2">
<br><br>
<input type="submit" name="submit">
<?php
if(isset($_POST['submit'])){
$real1=$_POST['real1'];
$imag1=$_POST['imag1'];
$real2=$_POST['real2'];
$imag2=$_POST['imag2'];
$sum1=$real1 + $real2;
$sum2=$imag1 + $imag2;
echo"<h2>addition of complex number is $sum1+$sum2";
echo "i";}
?>
</body>
</html>

Addition of Real and Imaginary numbers with a database

<html>
<head>
<style>
div {
	
border: solid black;
background-color:#00FF33;
align:center;
	width:900px;
	height:400px;

padding: 20px;
}

</style>
</head>
<body>
<div>
<h1>Assigment 3</h1>
<h2>Addition of Real and Imaginary</h2>
<form method="post">
Type 1st real number:<input type="text" name="real1">
Type 1st imaginary number:<input type="text" name="imag1"><br><br>
Type 2nd real number:<input type="text" name="real2">
Type 2nd imaginary number:<input type="text" name="imag2"><br><br>
<input type="submit" name="submit">
<?php
$con=mysqli_connect("localhost","root","","add");
if(isset($_POST['submit'])){
$real1=$_POST['real1'];
$imag1=$_POST['imag1'];
$real2=$_POST['real2'];
$imag2=$_POST['imag2'];
$sum1=$real1 + $real2;
$sum2=$imag1 + $imag2;
$sql=mysqli_query($con,"INSERT INTO comp(real,img) VALUES ('$sum1','$sum2')");
echo"<h2>addition of complex number is $sum1+$sum2";
echo "i";}
?>
</div>
</body>
</html>
Figure: Addition of Real and Imaginary numbers in PHP MySQL
Exit mobile version