0% found this document useful (0 votes)
9 views

Lab Manual

The document outlines a series of experiments focused on PHP programming, including creating simple web pages, using conditional statements, loops, user-defined functions, and handling file uploads. Each experiment has specific aims and objectives, demonstrating the application of PHP in dynamic webpage development and data management. Additionally, it includes examples of code for practical implementation and references to textbooks for further reading.

Uploaded by

preeti
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Lab Manual

The document outlines a series of experiments focused on PHP programming, including creating simple web pages, using conditional statements, loops, user-defined functions, and handling file uploads. Each experiment has specific aims and objectives, demonstrating the application of PHP in dynamic webpage development and data management. Additionally, it includes examples of code for practical implementation and references to textbooks for further reading.

Uploaded by

preeti
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Lab Manual Experiment-1.

1
CO1- Apply concept of html, css for web page development.

Experiment-1

Aim:

a. Creating simple webpage using PHP.

b. Use of conditional statements in PHP.

Objective: To utilize the basic components of PHP for better understandability

Solution:

<!DOCTYPE html>

<html>

<body>

<h1>My first PHP page</h1>

<?php

echo "Hello World!";

?>

</body>

</html>

b. Use of conditional statements in PHP.

<?php

$t = date("H");

if ($t < "20") {

echo "Have a good day!";

?>
Experiment-1.2
CO1-Apply concept of html, css for web page development.

Experiment-2

Aim: Use of conditional statements in PHP.

Objective: To utilize the basic concepts of PHP in order to ensure dynamic webpage creation

Solution: Use of conditional statements in PHP.

<?php

$x = 1;

while($x <= 5) {

echo "The number is: $x <br>";

$x++;

?>

<?php

$Pass_Mark=35;

$Student_Mark=70;

if ($Student_Mark>= $Pass_Mark){

echo “The Student is Eligible for the Promotion”;

?>

b. Creating different types of arrays.

<!DOCTYPE html>

<html>

<body>

<?php

$cars = array("Volvo", "BMW", "Toyota");

echo count($cars);

?>

</body>
</html>

Experiment-1.3
CO2-Analyse the function of php as a dynamic webpage creating tool.

Aim: Use of looping statements in PHP

Objective: To utilize the basic concepts of PHP in order to ensure dynamic webpage creation

Create a script using a for loop to add all the integers between 0 and 30 and display the total.

Solution:-

<?php
$sum = 0;
for($x=1; $x<=30; $x++)
{
$sum +=$x;
}
echo "The sum of the numbers 0 to 30 is $sum"."\n";
?>
Experiment_1.4
CO2-Analyse the function of php as a dynamic webpage creating tool.

Experiment-4

Aim: Creating user defined functions using PHP.

Objective: simple function which will display a simple "Merry Christmas and a Very Happy New Year"
message. This script can actually be very useful when you have to send festive emails to every friend
of yours and you have to write the same message in all of them.
Solution:

<?php
// defining the function
function greetings()0
{
echo "Merry Christmas and a Very Happy New Year";
}

echo "Hey Martha <br/>";


// calling the function
greetings();

// next line
echo "<br/>";

echo "Hey Jon <br/>";


// calling the function again
greetings();

?>

TextBooks

1.Steven Holzner, Wordpress-The Complete Reference, McGraw-Hill.

2. Robin Nixon, Wordpress-MySQL-JavaScript, O’Reilly.

Experiment_2.1
Experiment-5

Aim: Creating application using PHP in which implement properties

 Objective:- PHP class called 'Student' with properties like 'name', 'age', and 'grade'.
Implement a method to display student information. The "Student" class has three public
properties: $name, $age, and $grade, which represent the student's name, age, and grade.The
"displayInfo()" method is implemented to display student information by echoing the values of
the properties.
(a) Creating application using PHP in which implement properties

<?php

class Student {

public $name;

public $age;

public $grade;

public function displayInfo() {

echo "Name: " . $this->name . "</br>";

echo "Age: " . $this->age . "</br>";

echo "Grade: " . $this->grade . "</br>";

$student = new Student();

$student->name = "Gwladus Andrea";

$student->age = 16;

$student->grade = 10;

$student->displayInfo();

?>

b) Creating application using PHP in which implement File Uploading & Downloading <!DOCTYPE html>
<?php
if(isset($_FILES['image'])){

$errors= array();

$file_name = $_FILES['image']['name'];

$file_size =$_FILES['image']['size'];

$file_tmp =$_FILES['image']['tmp_name'];

$file_type=$_FILES['image']['type'];

$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));

$extensions= array("jpeg","jpg","png");

if(in_array($file_ext,$extensions)=== false){

$errors[]="extension not allowed, please choose a JPEG or PNG file.";

}
if($file_size > 2097152){

$errors[]='File size must be excately 2 MB';

if(empty($errors)==true){

move_uploaded_file($file_tmp,"images/".$file_name);

echo "Success";

}else{

print_r($errors);

?>

<html>

<body>

<form action="" method="POST" enctype="multipart/form-data">

<input type="file" name="image" />

<input type="submit"/>

</form>

</body>

</html>

It will produce the following result −

Experiment‌‌6
Creating simple table with constraints
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// sql to create table


$sql = "CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)";

if ($conn->query($sql) === TRUE) {


echo "Table MyGuests created successfully";
} else {
echo "Error creating table: " . $conn->error;
}

$conn->close();
?>

You might also like