Next Prime Number Program in PHP with Form and Database
Next Prime Number Program in PHP with Form and Database.
Next Prime Number Program in PHP
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 21 22 23 24 25 26 27 28 29 30 31 |
<html> <body> <center> <h2>Program 1</h2> <p>Next Prime number program in PHP </p> <?php $NextPrime=0; $Counter=2; $num=17; for($NextPrime=$num+1;$NextPrime<10000;$NextPrime++) { for($Counter=2;$Counter<$NextPrime;$Counter++) { if($NextPrime %$Counter==0) { break; } } if($NextPrime==$Counter || $NextPrime==1) { echo"You entered $num and next prime is $NextPrime"; break; } } ?> </center> </body> </html> |
Next Prime Number Program in PHP 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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
<html> <body> <center> <h2>Program 2</h2> <p>Next Prime number program in PHP (Using Form )</p> <h2> <form method="post"> <label>Enter any number</label><br /> <input type="text" name="number" /><br /> <input type="submit" name="submit" /> <br /><br /> </form></h2> <?php $NextPrime=0; $Counter=2; $num=$_POST['number']; for($NextPrime=$num+1;$NextPrime<10000;$NextPrime++) { for($Counter=2;$Counter<$NextPrime;$Counter++) { if($NextPrime %$Counter
==0) { break; } } if($NextPrime==$Counter || $NextPrime==1) { echo"You entered $num and next prime is $NextPrime"; break; } } ?> </center> </body> </html> |
Next Prime Number Program in PHP with 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 39 40 41 42 43 44 |
<html> <body> <center> <h2>Program 3</h2> <p>Next Prime number program in PHP (Using Form with SQL)</p> <h2> <form method="post"> <label>Enter any number</label><br /> <input type="text" name="number" /><br /> <input type="submit" name="submit" /> <br /><br /> </form></h2> <?php $con=mysqli_connect("localhost","root","","test2"); if(isset($_POST['submit'])) { $NextPrime=0; $Counter=2; $num=$_POST['number']; for($NextPrime=$num+1;$NextPrime<10000;$NextPrime++) { for($Counter=2;$Counter<$NextPrime;$Counter++) { if($NextPrime %$Counter==0) { break; } } if($NextPrime==$Counter || $NextPrime==1) { echo"You entered $num and next prime is $NextPrime"; break; } } $sql=mysqli_query($con,"INSERT INTO nextprime (Input,NextPrime) VALUES ($num,$NextPrime)"); } ?> </center> </body> </html> |
Database of Next Prime Number Program