PHP program to find the Fibonacci series with form and database
PHP program to find the Fibonacci series with form and database
In this tutorial, we will learn about the followings;
- PHP program to find the Fibonacci series with form and database
- PHP program to find the Fibonacci series with form and database
- PHP program to find the Fibonacci series with form and database
PHP program to find the Fibonacci series.
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<html> <body> </body> </html> <?php function F($n) { $number1 = 0; $number2 = 1; echo "Fibonacci Series \n"; echo $number1.' '.$number2.' '; for($i = 2; $i < $n; $i++){ $number3 = $number1 + $number2; echo $number3.' '; $number1 = $number2; $number2 = $number3; } } F(2); ?> |
PHP program to find the Fibonacci series with form.
In this example, we will take the inputs from the user and store them in variables.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
<html> <body> <form method="post"> <input type="text" name="Number" > <button name="submit">Submit</button> </form> </body> </html> <?php if (isset($_POST['submit'])) { $n=$_POST['Number']; $number1 = 0; $number2 = 1; echo "Fibonacci Series \n"; echo $number1.' '.$number2.' '; for($i = 2; $i < $n; $i++){ $number3= $number1 + $number2; echo $number3.' '; $number1 = $number2; $number2 = $number3; } } ?> |
PHP program to find the Fibonacci series with the 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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<html> <body> <form method="post"> <input type="text" name="Number" > <button name="submit">Submit</button> </form> </body> </html> <?php $conn = mysqli_connect('localhost','root','','fibonacci'); if (isset($_POST['submit'])) { $n=$_POST['Number']; $number1 = 0; $number2 = 1; echo "Fibonacci Series \n"; echo $number1.' '.$number2.' '; for($i = 2; $i < $n; $i++){ $number3= $number1 + $number2; echo $number3.' '; $number1 = $number2; $number2 = $number3; $temp=' '.$number3; } $sql= "INSERT INTO fib (result) VALUES('$temp')"; if($conn->query($sql)=== TRUE) { echo"<font color=#FF00FF> New Record Inserted<br></font>"; } else { echo"Error:".$sql."<br>".$conn->error; }} //function F($n) //{ //} //F(2); ?> |
Database to find the Fibonacci series