Nothing Special   »   [go: up one dir, main page]

Daksha

Download as pdf or txt
Download as pdf or txt
You are on page 1of 31

Enrollment no: 230841102038

PRACTICAL-1

1
Enrollment no: 230841102038

AIM: [A] Write a PHP script to display Welcome message.

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

echo "a is the greatest";


}
else
{
echo "c is the greatest";
}

}
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

AIM:[A] Write PHP Script for addition of two 2x2 matrices.


INPUT:
<?php
$a=array(array(6,2),array(11,3));
$b=array(array(5,3),array(4,3));

echo "Matrix Addition <br>";

for($i=0;$i<2;$i++)
{
for($j=0;$j<2;$j++)
{
echo $a[$i] [$j]+$b[$i] [$j]."";
}
echo "<br>";
}
?>

OUTPUT:

AIM:[B] Write PHP Script to print Fibonacci series.


INPUT:
<?php
$num = 0;
$n1 = 0;
$n2 = 1;

5
Enrollment no: 230841102038

echo "<h3>Fibonacci series for N number: </h3>";


echo "\n";
echo $n1.' '.$n2. ' ';

for($num = 0; $num < 12; $num = $num + 1){


$n3 = $n1 + $n2;
echo $n3.' ';
$n1 = $n2;
$n2 = $n3;
}
?>

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:

AIM:[B] Write PHP script to demonstrate Math functions.


INPUT:

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

AIM:[C] Write PHP script to demonstrate File functions.


INPUT:
<?php
$file = fopen("demo.txt" , 'r');
$file = fopen("demo.txt" , 'w');
$text = "Hello world\n";
fwrite($file, $text);
echo "$text";
fclose($file);
?>

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">

<form method="post" action="welcome.php">

<h2>Student Registration</h2>

12
Enrollment no: 230841102038

<input type="text" name="fname" placeholder="First Name">


<input type="text" name="lname" placeholder="Last Name">
<input type="email" name="email" placeholder="Email">
<input type="text" name="mobile" placeholder="Mobile">
<br>
<hr>
Gender<br>
<input type="radio" name="gender" value="Male">Male<br>
<input type="radio" name="gender" value="female">Female<br>
<hr>
Hobbies<br>
<input type="checkbox" name="hobby[]" value="Cricket">Cricket<br>
<input type="checkbox" name="hobby[]" value="Vollyball">Vollyball<br>
<input type="checkbox" name="hobby[ ]" value="Badminton">Badminton<br>
<hr>
<input type="Password" name="pass" placeholder="Password"><br>
<input type="submit" name="submit" value="Register">
</form>
</div>
</body>
</html>
Welcome.php
<?php
if(isset($_POST['submit']))
{
$fn=$_POST['fname'];
$ln=$_POST['lname'];
$em=$_POST['email'];
$mob=$_POST['mobile'];
$gender=$_POST['gender'];
$hobies=$_POST['hobby'];
$pass=$_POST['pass'];

echo "First name : $fn <br><br>";


echo "Last name : $ln <br><br>";
echo "Email : $em <br><br>";
echo "Mobile : $mob <br><br>";
echo "Gender : $gender <br><br>";

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">Email Id:</label>


<input type="text" id=" Email ID"><br><br>

<label for="name">Password:</label>
<input type="text" Name=" Password"><br><br>

<label for="name">Moblie no:</label>


<input type="text" id=" Moblie no"><br><br>

<label for="name">Address:</label>
<input type="text" id=" Address"><br><br>

<label for="name">Website URL:</label>


<input type="text" id=" Website URL"><br><br>

<label for="profile-pic">Profile Picture:</label>


<input type="file" id="profile-pic"><br><br>

16
Enrollment no: 230841102038

<label for="dob">Date of Birth:</label>


<input type="date" id="dob"><br><br>

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>

<input type="checkbox" id="terms" name="terms">


<label for="terms">I agree to the terms and
conditions</label><br><br>

<input type="submit" name="submit" value="Submit">

</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);

echo "your name is: ".$_COOKIE['myname'];

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";

$conn = mysqli_connect($servername, $username, $password, $dbname);

if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
} else {
echo "Connected successfully to MySQL database!";
}

mysqli_close($conn);
?>

OUTPUT:

26
Enrollment no: 230841102038

AIM: [B] Write a program to read students information like enrollment_number,


first_name, last_name, semester, and contact_number, from students table and
display all these information in table format on output screen .
INPUT:
<?php

$con = mysqli_connect('localhost', 'root', '', 'school');

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

$sql = "SELECT * FROM students";


$query = mysqli_query($con, $sql);

while ($raw = mysqli_fetch_assoc($query)) {


?>
<tr>
<td><?php echo $raw['enrollment_number']; ?></td>
<td><?php echo $raw['first_name']; ?></td>
<td><?php echo $raw['last_name']; ?></td>
<td><?php echo $raw['semester']; ?></td>
<td><?php echo $raw['contact_number']; ?></td>
</tr>
<?php
}
?>
</table>

27
Enrollment no: 230841102038

</body>
</html>

OUTPUT:

28
Enrollment no: 230841102038

PRACTICAL-8

29
Enrollment no: 230841102038

AIM: [A] Write a program to edit name of students to “XYZ” with


'enrollment_number'=1, and to delete record with 'enrollment_number'=3.
INPUT:
<?php

$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

You might also like