PHP Jurnal Final
PHP Jurnal Final
1. Develop a PHP program to display prime numbers between the given ranges
and display the total number of prime numbers.
<?php
$number=1;
while($number <50)
{
$div_count=0;
for ($i=1;$i<=$number;$i++)
{
if(($number%$i)==0)
{
$div_count++;
}
}
if($div_count<3)
{
echo $number." , ";
}
$number=$number+1;
}
?>
*************************OUTPUT*********************************
2. Develop a PHP program and check message passing mechanism between pages.
form1.php
<html>
<body>
<form action="welcome1.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
welcome1.php
<html>
<body>
Welcome <?php echo $_POST["fname"]; ?>.<br />
You are <?php echo $_POST["age"]; ?> years old!
</body>
</html>
*******************OUTPUT***********************
**************************OUTPUT***************************
?>
<br/>
<?php
$cars=array("Volvo","BMW","Toyota");
echo count($cars);
?>
<br/>
<?php
$cars=array("Volvo","BMW","Toyota");
echo sizeof($cars);
?>
</body>
</html>
*******************OUTPUT***********************
6.Write a PHP program that displays a different message based on time of day. For
example page should display “Good Morning” if it is accessed in the morning
<?php
date_default_timezone_set("Asia/Kolkata");
$h=date('G');
if($h>=5 && $h<=11)
{
echo "good morning";
}
else if($h>=12 && $h<=15)
{
echo "good afternoon";
}
else if($h>=18 && $h<=21)
{
echo "good evening";
}
else
{
echo "good night";
}
?>
*******************OUTPUT***********************
7.Write a PHP program that accepts two numbers using a web form and calculates
greatest common divisor (GCD) and least common multiple (LCM) of entered
numbers.(Use recursive function)
<?php
function getGCD($a, $b)
{
if ($b == 0)
{
return $a;
}
Else
{
return getGCD($b, $a % $b);
}
}
function getLCM($a, $b)
{
return ($a * $b) / getGCD($a, $b);
}
?>
<?php
if (!isset($_POST['submit']))
{
?>
<form method="post" action="gcf_lcm.php">
Enter two integers: <br />
<input type="text" name="num_1" size="4" />
<p>
<input type="text" name="num_2" size="4" />
<p>
<input type="submit" name="submit" value="Submit" />
</form>
<?php
}
else
{
$num1 = (int)$_POST['num_1'];
$num2 = (int)$_POST['num_2'];
echo "You entered: $num1, $num2";
echo "<br />";
echo "The GCD of ($num1, $num2) is: " . getGCD($num1, $num2);
echo "<br />";
echo "The LCM of ($num1, $num2) is: " . getLCM($num1, $num2);
}
?>
</body>
</html>
*******************OUTPUT***********************
*******************OUTPUT***********************
9. Develop a PHP code to read the values entered into the form using the MySQL database.
Connection.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "mydb";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
Registration.php
<?php
if(isset($_POST['register']))
{
include 'index.php';
$name = $_POST['name'];
$un = $_POST['username'];
$email = $_POST['email'];
$pass = $_POST['password'];
$conpass = $_POST['conpassword'] ;
$query = "INSERT INTO registration(name, username, email, Password, ConPassword) VALUES
('$name', '$un','$email', '$pass', '$conpass')";
mysqli_close($conn);
}
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" integrity="sha384-
Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
crossorigin="anonymous">
</head>
<body>
<h2>HTML Forms</h2>
</form>
<table class="table">
<thead>
<tr>
<th scope="col">name</th>
<th scope="col">username</th>
<th scope="col">email</th>
<th scope="col">password</th>
<th scope="col">delete</th>
<th scope="col">update</th>
</tr>
</thead>
<tbody>
<?php
include 'index.php';
$query = "SELECT * FROM registration";
$result = mysqli_query($conn, $query);
while($rows = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $rows['name']; ?></td>
<td><?php echo $rows['username']; ?></td>
<td><?php echo $rows['email']; ?></td>
<td><?php echo $rows['Password']; ?></td>
<td><a href='crud.php?del_user=<?php echo $rows['name']; ?>'><button type="submit"
class="btn btn-danger btn-sm" style="font-size: 12px;" style="border-
radius:50px">DELETE</button></a></td>
<td><a href='update.php?update_user=<?php echo $rows['name']; ?>'><button type="submit"
class="btn btn-danger btn-sm" style="font-size: 12px;" style="border-
radius:50px">update</button></a></td>
</tr>
<?php
}
?>
</body>
</html>
CRUD.php
<?php
include 'index.php';
if(isset($_GET['del_user']))
{
$id = $_GET['del_user'];
$query = "DELETE FROM registration WHERE name= '$id'";
*******************OUTPUT***********************
10. Create Laravel Project using composer display Simple “Hello World” Message on Web page.
routes\web.php
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/helloview', function () {
return view('hello');
});
resources\views\hello.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
*******************OUTPUT***********************