Rishit WFS
Rishit WFS
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:-202345027
Output:-
2 | Page
Div:-A Web Framework & Services Roll No:-202345027
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:-202345027
4 | Page
Div:-A Web Framework & Services Roll No:-202345027
<td>Rishit</td>
<td>Male</td>
<td>O+</td>
<td>15/12/2002</td>
<td>Surat</td>
<td>9765274382</td>
<td>[email protected]</td>
<td>Dengue</td>
<td>Vivek</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:-202345027
QUESTION: 3
Perform CRUD Operation for the patient. Also provide search patient
facility.
Code:-
connection.php:-
<?php
$objCon = mysqli_connect("localhost", "root", "", "stud_1");
function fnFetchStudents($offset, $recordsPerPage, $search = null){
global $objCon;
$sqlQuery = "SELECT * FROM patient_info";
if ($search !== null) {
$sqlQuery .= " WHERE pname LIKE '%$search%'"; }
$sqlQuery .= " LIMIT $offset, $recordsPerPage";
$resResult = mysqli_query($objCon, $sqlQuery);
$arrResult = array();
while ($data = mysqli_fetch_assoc($resResult)) {
$arrResult[] = $data; }
return $arrResult; }
function fnGetResult($sqlQuery){
global $objCon;
$resResult = fnFireQuery($sqlQuery);
return mysqli_fetch_assoc($resResult); }
function fnFireQuery($sqlQuery){
global $objCon;
return mysqli_query($objCon, $sqlQuery); }
function fnRedirectUrl($strRedirectUrl){
if (!headers_sent()) {
header("Location:" . $strRedirectUrl);
exit;
} else {
?>
<script type="text/javascript">
location.href = '<?php echo $strRedirectUrl; ?>';
</script>
<?php
}}?>
Listing.php:-
<?php
include_once "connection.php";
$recordsPerPage = 3;
$currentpage = isset($_GET['page']) ? intval($_GET['page']) : 1;
$offset = ($currentpage - 1) * $recordsPerPage;
6 | Page
Div:-A Web Framework & Services Roll No:-202345027
?>
<html>
<head>
<title>Patient Management Application</title>
<link rel="stylesheet" href="custom.css" />
</head>
<body>
<div class="container">
<div class="message">
<?php include_once "message.php"; ?>
</div>
<div class="action">
<button type="button" onclick="location.href='add.php'"><span>Add
Student</span></button></div>
<form action="listing.php" method="GET">
<input type="text" name="search" placeholder="Search by name..."
value="<?php //echo $_GET['search'] ?>">
<button type="submit">Search</button></form>
<table>
<tr>
<th>ID</th>
<th>Pname</th>
<th>Pcity</th>
<th>Page</th></tr>
<?php
$search = isset($_GET['search']) ? $_GET['search'] : '';
if ($search) {
$arrResult = fnFetchStudents($offset, $recordsPerPage,
$search);
} else {
$arrResult = fnFetchStudents($offset, $recordsPerPage); }
$totalRecords = count(fnFetchStudents($offset, $recordsPerPage));
$totalPages = ceil($totalRecords / $recordsPerPage);
echo '<div class="pagination">';
for ($i = 1; $i <= $totalRecords; $i++) {
$paginationLink = 'listing.php?page=' . $i;
if (!empty($search)) {
$paginationLink .= '&search=' . urlencode($search);}
echo '<a href="' . $paginationLink . '">' . $i . '</a>';
if ($i < $totalPages) {
echo " "; }}
if ($currentpage > $currentpage - 1) {
$nextPage = $currentpage + 1;
$nextPageLink = 'listing.php?page=' . $nextPage;
if (!empty($search)) {
$nextPageLink .= '&search=' . urlencode($search); }
if (empty($totalRecords)) {
7 | Page
Div:-A Web Framework & Services Roll No:-202345027
Add.php:-
<?php
include_once "connection.php";
if(isset($_POST['btnSaveStudent'])){
8 | Page
Div:-A Web Framework & Services Roll No:-202345027
$strName = trim($_POST['txtpname']);
$strcity = trim($_POST['txtpcity']);
$strage = trim($_POST['txtage']);
$sqlQuery = "INSERT INTO patient_info SET pname='".$strName."', pcity='".
$strcity."',p_age='".$strage."' ";
fnFireQuery($sqlQuery);
$strRedirectUrl = 'listing.php?m=2';
fnRedirectUrl($strRedirectUrl);}
?>
<html>
<head>
<title>Student Management Application</title>
<link rel="stylesheet" href="custom.css" /></head>
<body>
<div class="container">
<form action="add.php" method="post">
<table>
<tr>
<td>Pname</td>
<td><input type="text" name="txtpname" /></td></tr>
<tr>
<td>Pcity</td>
<td><input type="text" name="txtpcity" /></td></tr>
<tr>
<td>P_age</td>
<td><input type="text" name="txtage" /></td></tr>
</table>
<div class="action">
<button type="submit" name="btnSaveStudent"><span>Save
Student</span></button></div></form></div>
</body>
</html>
Output :-
Edit.php:-
<?php
include_once "connection.php";
if (isset($_POST['btnSaveStudent'])) {
$intpId = trim($_POST['hdnID']);
9 | Page
Div:-A Web Framework & Services Roll No:-202345027
$strName = trim($_POST['txtName']);
$strcity = trim($_POST['txtcity']);
$strage = trim($_POST['txtage']);
$sqlQuery = " UPDATE patient_info SET pname='" . $strName . "', pcity='" . $strcity .
"',p_age='" . $strage . "' WHERE id='" . $intpId . "' ";
fnFireQuery($sqlQuery);
$strRedirectUrl = 'listing.php?m=3';
fnRedirectUrl($strRedirectUrl);
}
?>
<html>
<head>
<title>Patient Management Application</title>
<link rel="stylesheet" href="custom.css" /></head>
<body>
<div class="container">
<form action="edit.php" method="post">
<input type="hidden" name="hdnID" value="<?php echo $_GET['id']; ?>" />
<?php
$arrSpecStudent = array();
$sqlQuery = " SELECT * FROM patient_info WHERE id = " . $_GET['id'];
$arrSpecStudent = fnGetResult($sqlQuery);
?>
<table>
<tr>
<td>Name</td>
<td><input type="text" name="txtName" value="<?
php echo $arrSpecStudent['pname']; ?>" /></td></tr>
<tr>
<td>City</td>
<td><input type="text" name="txtcity" value="<?php
echo $arrSpecStudent['pcity']; ?>" /></td></tr>
<tr>
<td>Age</td>
<td><input type="text" name="txtage" value="<?php
echo $arrSpecStudent['p_age']; ?>" /></td></tr></table>
<div class="action">
<button type="submit" name="btnSaveStudent"><span>Save
Student</span></button>
</div></form></div>
</body>
</html>
10 | P a g e
Div:-A Web Framework & Services Roll No:-202345027
Output :-
Delete.php:-
<?php
include_once "connection.php";
$intId = $_GET['id'];
$sqlQuery = " DELETE FROM patient_info WHERE id = ".$intId;
fnFireQuery($sqlQuery);
$strUrl = 'listing.php?m=1';
fnRedirectUrl($strUrl);
?>
Output :-
11 | P a g e
Div:-A Web Framework & Services Roll No:-202345027
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">
12 | P a g e
Div:-A Web Framework & Services Roll No:-202345027
13 | P a g e
Div:-A Web Framework & Services Roll No:-202345027
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
14 | P a g e
Div:-A Web Framework & Services Roll No:-202345027
</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>
15 | P a g e
Div:-A Web Framework & Services Roll No:-202345027
Output:-
16 | P a g e
Div:-A Web Framework & Services Roll No:-202345027
QUESTION:5
Write a python program to perform Count Visitors of Page and call it
using PHP
Code:-
Count_Visitors.py:-
import sys;
if sys.argv[1]:
intCounter = sys.argv[1]
else:
intCounter = 1;
print(int(intCounter)+1);
Count_Visitors.php:-
<?php
if(!isset($_COOKIE['visitor_count'])){
$strComand = escapeshellcmd("python visitor_count.py 1");
$intCounter = shell_exec($strComand);
setcookie("visitor_count",$intCounter, time() + 86400);
echo "Total Visitor:".$intCounter;}
else{
$intCounter = $_COOKIE['visitor_count'];
$strComand = escapeshellcmd("python visitor_count.py $intCounter");
$intCounter = shell_exec($strComand);
setcookie("visitor_count",$intCounter, time() + 86400);
echo "Total Visitor:".$intCounter; }
?>
Output:-
17 | P a g e
Div:-A Web Framework & Services Roll No:-202345027
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:-
Create Album:-
<?php
if (isset($_POST["create_album"])) {
$albumName = $_POST["album_name"];
if (!empty($albumName)) {
$albumDirectory = "C:/xampp/htdocs/Journal/albums/$albumName";
if (!is_dir($albumDirectory)) {
if (mkdir($albumDirectory, 0777, true)) {
echo "Album '$albumName' created successfully.";
} else {
echo "Error creating album directory.";
}
} else {
echo "Album '$albumName' already exists.";
}
} else {
echo "Album name cannot be empty.";
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Create Album</title>
</head>
<body>
<h1>Create Album</h1>
<form action="create_album_process.php" method="POST">
<label for="album_name">Album Name:</label>
<input type="text" name="album_name" required><br><br>
<input type="submit" name="create_album" value="Create Album">
</form>
</body>
18 | P a g e
Div:-A Web Framework & Services Roll No:-202345027
</html>
<?php
if (isset($_POST["upload_photos"])) {
$albumName = $_POST["album_name"];
$targetDirectory = "C:/xampp/htdocs/Journal/albums/$albumName/";
if (!is_dir($targetDirectory)) {
mkdir($targetDirectory, 0777, true);
}
if (isset($_FILES["photos"])) {
foreach ($_FILES["photos"]["tmp_name"] as $key => $tmp_name) {
$photoName = $_FILES["photos"]["name"][$key];
$targetFile = $targetDirectory . $photoName;
$fileExtension = strtolower(pathinfo($targetFile, PATHINFO_EXTENSION));
if (in_array($fileExtension, $allowedExtensions)) {
$uniqueFilename = uniqid() . "_" . $photoName;
$targetFile = $targetDirectory . $uniqueFilename;
if (move_uploaded_file($_FILES["photos"]["tmp_name"][$key], $targetFile)) {
echo "Photo '$uniqueFilename' uploaded successfully.";
} else {
echo "Error uploading photo '$photoName'.";
}
} else {
echo "Error: Invalid file type for '$photoName'. Only JPG, JPEG, PNG, and GIF files
are allowed.";
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Upload Photos</title>
</head>
<body>
<h1>Upload Photos</h1>
<form action="upload_photos_logic.php" method="POST" enctype="multipart/form-
19 | P a g e
Div:-A Web Framework & Services Roll No:-202345027
data">
<label for="album_name">Select Album:</label>
<select name="album_name" required>
<?php
$albumDirectory = "C:/xampp/htdocs/Journal/albums";
$albums = scandir($albumDirectory);
foreach ($albums as $album) {
if ($album != "." && $album != ".." && is_dir("$albumDirectory/$album")) {
echo "<option value='$album'>$album</option>";
}
}
?>
</select><br><br>
<input type="file" name="photos[]" multiple accept="image/*"><br><br>
<input type="submit" name="upload_photos" value="Upload Photos">
</form>
</body>
</html>
Display Album in Gallery:-
<!DOCTYPE html>
<html>
<head>
<title>Album Gallery</title>
</head>
<body>
<h1>Album Gallery</h1>
<h2>Select an Album:</h2>
<form action="view_album.php" method="POST">
<select name="album_name" required>
<?php
$albumDirectory = "C:/xampp/htdocs/Journal/albums";
$albums = scandir($albumDirectory);
foreach ($albums as $album) {
if ($album != "." && $album != ".." && is_dir("$albumDirectory/$album")) {
echo "<option value='$album'>$album</option>";
}
}
?>
</select>
<input type="submit" name="show_album" value="Show Album">
</form>
<?php
if (isset($_POST["show_album"])) {
$selectedAlbum = $_POST["album_name"];
$albumPath = "C:/xampp/htdocs/Journal/albums/$selectedAlbum";
20 | P a g e
Div:-A Web Framework & Services Roll No:-202345027
if (!is_dir($albumPath)) {
echo "Album directory not found.";
} else {
$photos = scandir($albumPath);
foreach ($photos as $photo) {
if ($photo != "." && $photo != "..") {
$fileInfo = pathinfo("$albumPath/$photo");
$extension = strtolower($fileInfo['extension']);
if (in_array($extension, ['jpg', 'jpeg', 'png', 'gif'])) {
echo "<div class='image-container'>";
echo "<p>Image Type: $extension</p>";
echo "<img src='$albumPath/$photo' alt='$photo'>";
echo "</div>";
}
}
}
}
}
?>
</body>
</html>
Subprocess.py:-
import subprocess
php_script_path = "C:/xampp/htdocs/Journal/view_album.php"
if result.returncode == 0:
print("PHP script executed successfully.")
print("Output:")
print(result.stdout)
else:
print("Error executing PHP script.")
print("Error Output:")
print(result.stderr)
21 | P a g e
Div:-A Web Framework & Services Roll No:-202345027
Output :-
22 | P a g e