Site icon T4Tutorials.com

PHP program to find the cube root of a number with form and database

PHP program to find the cube root of a number with form and database

In this tutorial, we will learn about the followings.

  1. PHP program to find the cube root of a number with form and database.
  2. PHP program to find the cube root of a number with form and database.
  3. PHP program to find the cube root of a number with form and database.

PHP program to find the cube root of a number.

In this example, programmer stores the values in the variables. However, if you interested to see the program about taking values in the form, please see example 2. 

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Cube Root</title>
</head>
<body>
<?php
$num=64;
$cube_root=pow($num,(1.0/3.0));
echo "Cube root of 64 is= $cube_root";
?>
</body>
</html>

PHP program to find the cube root of a number with form.

In this example, we will take the inputs from the user and store them in variables. 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Cube Root</title>
</head>
<body>
<form method="post">
Enter the number  <input type="text" name="Number" /><br />
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST['submit']))
{
$num=$_POST['Number'];
$cube_root=(pow($num,(1.0/3.0)));
echo "$cube_root";
}
?>
</body>
</html>

PHP program to find the cube root of a number with a database.

In this example, we will take the inputs from the user and temporarily store them in variables and then finally stores them permanently in the database.

<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>
<form  method="post">
<input type="text" name="name"/>
<input type="submit" name="OK" />
</form>
<?php  
$con=mysqli_connect("localhost","root","","CubeRootDB");
if(isset($_POST['OK'])){
$t =$_POST['name']; 
{
$cr=(pow($t,(1/3)));

//echo "<input value= $cr name = $cr/>";

}  
$sql=mysqli_query($con,"INSERT INTO pow (number,result) VALUES ('$t','$cr')");
echo "<input value= $cr />";
}
?> 
</body>
</html>

 

Database of PHP program to find the cube root of a number.

Figure: cube root PHP program database.

 

Exit mobile version