Darshan W Fs
Darshan W Fs
QUESTION: 1
Write a PHP script to sort the user defined array in either ascending or
descending order according to the user choice.
Code:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sorting array</title>
</head>
<body>
<div class="container">
<form ac on="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<label>Enter String or Number</label><br>
<input type="text" placeholder="Enter" name="first"><br>
<input type="text" placeholder="Enter" name="sec"><br>
<input type="text" placeholder="Enter" name="third"><br>
<input type="text" placeholder="Enter" name="fourth"><br>
<input type="text" placeholder="Enter" name="fifth"><br>
<button name='asc'>ascending</button>
<button name='dec'>descending</button>
</form>
<?php
1 | Page
Div:-A Web Framework & Services Roll No:-20234506062
Output:-
2 | Page
Div:-A Web Framework & Services Roll No:-20234506062
QUESTION: 2
Create a registration form for the patient with minimum 12 fields including
file upload facility for reports of the patients. Do necessary validations on
all the fields. (Design Only)
Code:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Journal Q2</title>
</head>
<body>
<form action="journal2.php" method="post">
<h1>Patient Details Form</h1>
<table border="2">
<tr>
<td>Patient Name:</td>
<td><input class="idata" type="text" name="pName" id="pName"></td>
<td class="hd">Patient Gender:</td>
<td>
<label for="male"><input class="idata" type="radio" name="gender" id="male">
Male</label>
<label for="female"><input class="idata" type="radio" name="gender" id="female">
Female</label>
</td>
</tr>
<tr>
<td class="hd">Blood Group:</td>
<td><input class="idata" type="text" name="bg" id="bg"></td>
<td class="hd">Date of Birth:</td>
<td><input class="idata" type="date" name="dob" id="dob"></td>
</tr>
<tr>
<td class="hd">Patient Address:</td>
<td><textarea class="idata" name="pAdd" id="pAdd" cols="25" rows="5"></textarea></td>
<td class="hd">Patient Contact:</td>
<td><input class="idata" type="number" name="pCon" id="pCon"></td>
</tr>
<tr>
<td class="hd">Patient Email:</td>
3 | Page
Div:-A Web Framework & Services Roll No:-20234506062
4 | Page
Div:-A Web Framework & Services Roll No:-20234506062
<td>Darshan</td>
<td>Male</td>
<td>O+</td>
<td>15/12/2004</td>
<td>Surat</td>
<td>9765274382</td>
<td>[email protected]</td>
<td>Cold</td>
<td>Rishit</td>
<td>8487283749</td>
<td>7/8/2022</td>
<td>negative</td>
<td><button class="btn red">Delete</button></td>
<td><button class="btn blue">Edit</button></td>
</tr>
</table>
</div>
</body>
</html>
Output:-
5 | Page
Div:-A Web Framework & Services Roll No:-20234506062
QUESTION: 3
Perform CRUD Operation for the patient. Also provide search patient
facility.
Code:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Journal Q3</title>
<!-- Add your CSS and JavaScript references here -->
</head>
<body>
<?php
$pname = "";
$bgroup = "";
$pgender = "";
$dob = "";
$paddress = "";
$pcon = "";
$pemail = "";
$pdis = "";
$drname = "";
$drcon = "";
$apdate = "";
$report = "";
$uid = "";
if (isset($_POST['submit'])) {
// Handle form submission
$pname = $_POST['pname'];
$bgroup = $_POST['bgroup'];
if (!empty($_POST['pgender'])) {
$pgender = $_POST['pgender'];
}
$dob = $_POST['dob'];
$paddress = $_POST['paddress'];
$pcon = $_POST['pcon'];
$pemail = $_POST['pemail'];
$pdis = $_POST['pdis'];
6 | Page
Div:-A Web Framework & Services Roll No:-20234506062
$drname = $_POST['drname'];
$drcon = $_POST['drcon'];
$apdate = $_POST['apdate'];
$report = $_POST['report'];
}
if (isset($_GET['uid'])) {
// Fetch data for editing
$con = mysqli_connect("localhost", "root", "", "demo");
$str = "SELECT * FROM `hospital` WHERE id=" . $_GET['uid'];
$r = $con->query($str);
$row = $r->fetch_assoc();
$pname = $row["pname"];
$pgender = $row["pgender"];
$bgroup = $row["bgroup"];
$dob = $row["dob"];
$paddress = $row["paddress"];
$pcon = $row["pcon"];
$pemail = $row["pemail"];
$pdis = $row["pdis"];
$drname = $row["drname"];
$drcon = $row["drcon"];
$apdate = $row["apdate"];
$report = ($row["report"] == "") ? $row['report'] : $row['report'];
}
if (isset($_POST['reset'])) {
// Reset form data
$pname = "";
$bgroup = "";
$pgender = "";
$dob = "";
$paddress = "";
$pcon = "";
$pemail = "";
$pdis = "";
$drname = "";
$drcon = "";
$apdate = "";
$report = "";
}
if (isset($_POST['update'])) {
// Handle data update
$uid = $_POST['uid'];
$pname = $_POST["pname"];
$pgender = $_POST["pgender"];
7 | Page
Div:-A Web Framework & Services Roll No:-20234506062
$bgroup = $_POST["bgroup"];
$dob = $_POST["dob"];
$paddress = $_POST["paddress"];
$pcon = $_POST["pcon"];
$pemail = $_POST["pemail"];
$pdis = $_POST["pdis"];
$drname = $_POST["drname"];
$drcon = $_POST["drcon"];
$apdate = $_POST["apdate"];
if (
$pname != "" && $bgroup != "" &&
$pgender != "" && $dob != "" &&
$paddress != "" && $pcon != "" &&
$pemail != "" && $pdis != "" &&
$drname != "" && $drcon != "" &&
$apdate != "" && $report != ""
){
$res = $con->query($str);
if ($res) {
header("Location: journal2.php");
}
}
}
?>
8 | Page
Div:-A Web Framework & Services Roll No:-20234506062
<div>
<table class="dtbl">
<tr>
<th>ID</th>
<th>pName</th>
<th>pGender</th>
<th>B-Group</th>
<th>DOB</th>
<th>pAddress</th>
<th>pContect</th>
<th>pEmail</th>
<th>pDisease</th>
<th>dr.Name</th>
<th>dr.Contect</th>
<th>Date</th>
<th>report</th>
<th>Delete</th>
<th>Edit</th>
</tr>
<!-- Populate the table with data from the database -->
</table>
</div>
<?php
if (isset($_GET['id'])) {
// Handle deletion of a record
$con = mysqli_connect("localhost", "root", "", "demo");
$id_to_delete = $_GET['id'];
$delete_query = "DELETE FROM `hospital` WHERE id=$id_to_delete";
$res = $con->query($delete_query);
if ($res) {
header("Location: javascript:history.go(-1)");
} else {
echo "Failed to delete record.";
}
}
?>
</body>
</html>
9 | Page
Div:-A Web Framework & Services Roll No:-20234506062
Output:-
10 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
QUESTION:4
Create a sign in form for patient. Upon Successful sign in patient can give
feedback about hospital using feedback form.
Create feedback Form.
Manage session and cookies between the logs in and log out process.
Code:-
Signin_Patient.php:-
<?php
// Check if 'id' is set in the URL
if (isset($_GET['id'])) {
// Get the user ID from the URL
$user_id = $_GET['id'];
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
11 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
12 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
Feedback.php:-
<!DOCTYPE html>
<html>
<head>
<link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
<style>
/* Add your CSS styles here */
body {
font-family: 'Open Sans', sans-serif;
}
.form_box {
/* Add your box styling here */
}
.pic {
/* Add styling for the radio button options here */
}
</style>
</head>
<body>
<div class="form_box shadow">
<form method="post" action="practice.php">
<div class="heading">Feedback Form</div>
<br/>
<p>What do you think about the quality of our blog?</p>
<div>
<div class="pic">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/f/fb/Emoji_u1f610.svg/
800px-Emoji_u1f610.svg.png" alt="" width="60">
<br/>
<label for="bad">
<input type="radio" name="quality" id="bad" value="0"> Bad
13 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
</label>
</div>
<div class="pic">
<img src="https://www.pinclipart.com/picdir/middle/228-2283979_emoji-
wikipedia-clipart.png" alt="" width="60">
<br/>
<label for="okay">
<input type="radio" name="quality" id="okay" value="1"> Okay
</label>
</div>
<div class="pic">
<img
src="https://upload.wikimedia.org/wikipedia/commons/thumb/9/90/Twemoji_1f600.svg/
220px-Twemoji_1f600.svg.png" alt="" width="60">
<br/>
<label for="good">
<input type="radio" name="quality" id="good" value="2"> Good
</label>
</div>
</div>
<p>Do you have any suggestions for us?</p>
<textarea name="suggestion" rows="8" cols="40"></textarea>
<input type="submit" name="submit" value="Submit Form">
</form>
</div>
</body>
</html>
14 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
Output:-
15 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
QUESTION:5
Write a python program to perform Count Visitors of Page and call it
using PHP
Code:-
Python Code:-
import os
def get_visitor_count():
count = 0
if os.path.exists(count_file):
with open(count_file, 'r') as file:
count = int(file.read())
return count
def increment_visitor_count():
count = get_visitor_count() + 1
with open(count_file, 'w') as file:
file.write(str(count))
if __name__ == '__main__':
increment_visitor_count()
print("Visitor Count Updated")
PHP Code:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Visitor Counter</title>
</head>
<body>
<h1>Welcome to My Page</h1>
<?php
// Read the visitor count from the file
$count_file = 'visitor_count.txt';
$visitor_count = 0;
if (file_exists($count_file)) {
$visitor_count = intval(file_get_contents($count_file));
}
16 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
</html>
Output:-
17 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
QUESTION:6
Write a PHP script to create Photo Album Application and call it using
python.
Create Album
Upload Photos in Album
Display Album in Gallery
Code:-
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Question5</title>
<link rel="stylesheet" href="home.css">
</head>
<body>
<?php
$pythonScriptPath = "photo.py";
$pythonScriptArgs = "Aditya";
$escapedScriptPath = escapeshellarg($pythonScriptPath);
$escapedScriptArgs = escapeshellarg($pythonScriptArgs);
$data = shell_exec("python $escapedScriptPath $escapedScriptArgs");
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
}
$albumName = "";
if (isset($_POST["btn"])) {
$albumName = $_POST["albumname"];
if (!empty($albumName)) {
$albumName = mysqli_real_escape_string($con, $albumName);
$query = "INSERT INTO `album` (name) VALUES ('$albumName')";
if ($con->query($query) === TRUE) {
$albumName = "";
} else {
echo "Error: " . $query . "<br>" . $con->error;
}
18 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
}
}
?>
<form action="home.php" method="post">
<div class="header">
<h3>Album Name :</h3>
<input type="text" name="albumname" id="albumname" value="<?php echo
htmlspecialchars($albumName); ?>">
<button type="submit" name="btn" class="btn">Add</button><br><br>
</div>
<div>
<?php
$query = "SELECT * FROM album";
$res = $con->query($query);
if ($res) {
$data = mysqli_fetch_all($res);
foreach ($data as $row) {
$albumId = $row[0];
$albumName = htmlspecialchars($row[1]);
19 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
Album.php:-
<!DOCTYPE html>
<html lang="en">
<?php
if (!isset($_GET['album'])) {
header("Location: home.php");
exit;
}
if (isset($_POST['back'])) {
header("Location: home.php");
exit;
}
$id = $_GET['album'];
$data = exec(escapeshellcmd("python yagnesh.py yagnesh"));
$data = explode(" ", $data);
$con = mysqli_connect($data[0], $data[1], $data[2], $data[3]);
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
header("Location: album.php?album=$id");
exit;
}
20 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
<title>myAlbum</title>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data" id="myform">
<div class="header">
<button class="btn" type="submit" name="back"> < </button>
<p class="name">
<?php
$str = "SELECT * FROM album where id=$id";
$res = $con->query($str);
$name = mysqli_fetch_row($res)[1];
echo $name;
?>
</p>
</div>
<?php
if (count($data) != 0) {
foreach ($data as $image) {
?>
<a href="image.php?id=<?php echo $image[0]; ?>">
<img class="img" src="<?php echo $image[1]; ?>" alt="image not found"
srcset="" height="200">
</a>
<?php
}
} else {
?>
<div class="no">no image</div>
<?php
}
?>
<label for="pic" class="add">+
<input type="file" name="pic" id="pic" onchange="form.submit();" hidden>
</label>
</form>
</body>
</html>
21 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
Image.php:-
<!DOCTYPE html>
<html lang="en">
<?php
if (!isset($_GET['id']) || empty($_GET['id'])) {
header("Location: home.php");
exit;
}
$id = $_GET['id'];
$data = exec(escapeshellcmd("python yagnesh.py yagnesh"));
$data = explode(" ", $data);
$con = mysqli_connect($data[0], $data[1], $data[2], $data[3]);
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
if (isset($_POST['back'])) {
header("Location: album.php?album=" . $data[2]);
exit;
}
if (count($data) <= 1) {
header("Location: home.php");
exit;
}
if (isset($_POST['p'])) {
$album = $data[2];
$str = "SELECT * FROM image WHERE album=" . $album;
$res = $con->query($str);
$dataArray = mysqli_fetch_all($res);
$num = array_search($data, $dataArray);
$img = $dataArray[$num + 1][0];
header("Location: image.php?id=" . $img);
exit;
}
if (isset($_POST['b'])) {
$album = $data[2];
$str = "SELECT * FROM image WHERE album=" . $album;
$res = $con->query($str);
22 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062
$dataArray = mysqli_fetch_all($res);
$num = array_search($data, $dataArray);
$img = $dataArray[$num - 1][0];
header("Location: image.php?id=" . $img);
exit;
}
?>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>image</title>
<link rel="stylesheet" href="image.css">
</head>
<body>
<form action="" method="post">
<div class="header">
<button class="btn" type="submit" name="back"><<</button>
<p class="name"><?php echo htmlspecialchars($data[1]); ?></p>
</div>
<div class="img">
<img class="image" src="<?php echo htmlspecialchars($data[1]); ?>" alt="" srcset="">
</div>
<div class="bottom">
<button class="bp" name="b" type="submit">↩</button>
<button class="bp" name="p" type="submit">↪</button>
</div>
</form>
</body>
</html>
Output:-
23 | P a g e