Daksha
Daksha
Daksha
PRACTICAL-1
1
Enrollment no: 230841102038
INPUT:
<?PHP
echo "Welcome to PHP Programming
!!!!"."<br>";
print("Welcome to PHP"."<br>");
print "Hello World";
?>
OUTPUT:
AIM: [B] Write PHP Script to find maximum number out of three given numbers.
INPUT:
<?php
$a = 100;
$b = 200;
$c = 300;
echo "a = $a b = $b c = $c"."<br>";
if ($a>$b)
{
if($a>$c)
{
2
Enrollment no: 230841102038
}
else
{
if ($b>$c)
{
echo "b is the greatest";
}
else
{
echo "c is the greatest";
}
}
?>
OUTPUT:
3
Enrollment no: 230841102038
PRACTICAL-2
4
Enrollment no: 230841102038
for($i=0;$i<2;$i++)
{
for($j=0;$j<2;$j++)
{
echo $a[$i] [$j]+$b[$i] [$j]."";
}
echo "<br>";
}
?>
OUTPUT:
5
Enrollment no: 230841102038
OUTPUT:
6
Enrollment no: 230841102038
PRACTICAL-3
7
Enrollment no: 230841102038
AIM:[A] Write PHP script to obtain factorial of given number Using function.
INPUT:
<?php
function fact($n){
if($n==0)
{
return 0;
}
else if($n==1)
{
return 1;
}
else
{
return $n*fact($n-1);
}
}
echo fact(5);
?>
OUTPUT:
8
Enrollment no: 230841102038
<?php
$n1=100;
$n2=5;
$n3=min($n1,$n2);
echo "Min is : $n3"."<br><br>";
$n1=Max ($n1,$n3);
echo "Max is : $n1"."<br><br>";
$n4=sqrt($n1);
echo "sqrt is : $n4"."<br><br>";
$n1=pow($n2,$n4);
echo "pow is : $n1". "<br><br>";
echo "ceil is :".ceil(5.6). "<br><br>";
echo "floor is :".floor(5.3). "<br><br>";
echo "round is :".round(56.32). "<br><br>";
echo "abs is :".abs(-2.662);
?>
OUTPUT:
9
Enrollment no: 230841102038
OUTPUT:
Demo.txt file
10
Enrollment no: 230841102038
PRACTICAL-4
11
Enrollment no: 230841102038
AIM:[A] Create student registration form using text box, check box, radio button,
select, submit button. And display user inserted value in new PHP page.
INPUT:
<html>
<head>
<title>Registration</title>
<style>
.main
{
width:30%;
margin:2em auto;
border:2px solid black;
padding:1em;
}
.main input[type="submit"]
{
width:95%;
border:1px solid black;
padding:.5em;
margin:.5em;
}
.main input[type="password"]
{
width:95%;
border:1px solid black;
padding:.5em;
margin:.5em;
}
.main input[type="text"],.main input[type="email"]
{
width:45%;
border:1px solid black;
padding:.5em;
margin:.5em;
}
</style>
</head>
<body>
<div class="main">
<h2>Student Registration</h2>
12
Enrollment no: 230841102038
echo "<h3>Hobbies</h3>";
$i=0;
13
Enrollment no: 230841102038
while($i<sizeof($hobies))
{
echo $hobies[$i]."<br>";
$i++;
}
}
?>
OUTPUT:
14
Enrollment no: 230841102038
AIM: [B] Create Website Registration Form using text box, check box, radio
button, select, submit button. And display user inserted value in new PHP page.
INPUT:
<html>
<head>
<titel>Registration</titel>
<style>
.main
{
width:30%;
margin: 2em auto;
border: 2px solid black;
padding: 1em;
}
.main input[type="submit"]
{
width:95%;
border:1px solid black;
15
Enrollment no: 230841102038
padding:.5em;
margin:.5em;
}
.main input[type="password"]
{
width:95%;
border:1px solid black;
padding:.5em;
margin:.5em;
}
.main input[type="text" ],.main input[type="email"]
{
width:45%;
border: 1px solid black;
padding:.5em;
margin:.5em;
}
</style>
</head>
<body>
<div class="main">
<center> <h1>Registration Form</h1></center>
<form action="#" method="POST">
<label for="name">User name:</label>
<input type="text" id=" user name"><br><br>
<label for="name">Password:</label>
<input type="text" Name=" Password"><br><br>
<label for="name">Address:</label>
<input type="text" id=" Address"><br><br>
16
Enrollment no: 230841102038
Gender:<br>
<input type="radio" name="gender" value="male">Male<br>
<input type="radio" name="gender" value="female">Female<br><br>
<Select name="Select"><br>
<option value="">Select city</option>
<option value="Vyara">Vyara</option>
<option value="Surat">Surat</option>
<option value="Pune">Pune</option>
<option value="Mumbai">Mumbai</option>
</Select><br><br>
</form>
</div>
</body>
</html>
OUTPUT:
17
Enrollment no: 230841102038
18
Enrollment no: 230841102038
PRACTICAL-5
19
Enrollment no: 230841102038
AIM: [A] Write two different PHP script to demonstrate passing variables through
a URL.
INPUT:
<?php
$fname="Krish";
$lname="Thakre";
?>
<a href="retrive.php?First_name=<?php echo $fname; ?>&last_name=<?php echo
$lname; ?>">
Click here to Pass Variable through URL
</a>
OUTPUT:
<?php
echo "First Name : ".$_GET['First_name']."<br>";
echo "Last Name : ".$_GET['last_name'];
?>
OUTPUT:
20
Enrollment no: 230841102038
AIM: [B] Write two different PHP script to demonstrate passing variables with
sessions.
INPUT:
<html>
<head>
<title>Session</title>
</head>
<form method="post" action="retrive1.php">
Enter Your name : <input type="text" name="fname"><br>
<input type="submit" name="submit" value="Create session">
</form>
</html>
OUTPUT:
<?php
session_start();
if(isset($_POST['submit']))
{
$sr=$_POST['fname'];
$_SESSION['sr']=$sr;
echo "Your name is : ".$_SESSION['sr'];
}
?>
21
Enrollment no: 230841102038
AIM: [C] Write PHP script to demonstrate passing variables with cookies.
INPUT:
<html>
<head>
<title>Cookie</title>
</head>
<body>
<form method = "post">
Enter your name: <input type = "text" name = "fname" value = "<?php echo
isset($_COOKIE['myname']) ? $_COOKIE['myname'] : ''; ?>">
<input type = "submit" value = "Create Cookie" name = "submit">
</form>
</body>
</html>
OUTPUT:
<?php
if(isset($_POST['submit'])){
$name = $_POST['fname'];
setcookie('myname',$name,time()+100,"/","",0);
if(!isset($_COOKIE['myname'])){
echo "failed to create cookie";
}
}
?>
22
Enrollment no: 230841102038
PRACTICAL-6
23
Enrollment no: 230841102038
AIM: Write a program to keep track of how many times a visitor has loaded the
page.
INPUT:
<?php
$handle = fopen("counter.txt", "r");
if(!$handle)
{
echo "could not open the file" ;
}
else
{
$counter = (int ) fread($handle,20);
fclose ($handle);
$counter++;
echo" <strong> you are visitor no ". $counter . " </strong> " ;
$handle = fopen("counter.txt", "w" );
fwrite($handle,$counter);
fclose($handle);
}
?>
OUTPUT:
24
Enrollment no: 230841102038
PRACTICAL-7
25
Enrollment no: 230841102038
AIM: [A] Write a PHP script to connect MySQL server from your website.
INPUT:
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "school";
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
} else {
echo "Connected successfully to MySQL database!";
}
mysqli_close($conn);
?>
OUTPUT:
26
Enrollment no: 230841102038
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
?>
<html>
<head>
<title>Display From Database</title>
</head>
<body>
<table border="1">
<tr>
<th>Enrollment_No</th>
<th>First Name</th>
<th>Last Name</th>
<th>Semester</th>
<th>Contact No</th>
</tr>
<?php
27
Enrollment no: 230841102038
</body>
</html>
OUTPUT:
28
Enrollment no: 230841102038
PRACTICAL-8
29
Enrollment no: 230841102038
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "school";
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$update_sql = "UPDATE students SET first_name = 'XYZ' WHERE
enrollment_number = 1";
if (mysqli_query($conn, $update_sql)) {
echo "Record updated successfully for enrollment_number = 1.<br>";
} else {
echo "Error updating record: " . mysqli_error($conn) . "<br>";
}
$delete_sql = "DELETE FROM students WHERE enrollment_number = 3";
if (mysqli_query($conn, $delete_sql)) {
echo "Record deleted successfully for enrollment_number = 3.<br>";
} else {
echo "Error deleting record: " . mysqli_error($conn) . "<br>";
}
mysqli_close($conn);
?>
OUTPUT:
30
Enrollment no: 230841102038
31