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

Darshan W Fs

Uploaded by

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

Darshan W Fs

Uploaded by

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

Div:-A Web Framework & Services Roll No:-20234506062

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

// Check if form is submitted


if ($_SERVER['REQUEST_METHOD'] == 'POST') {
// Get values
$num = [];
// Check if array keys are set before accessing them
if (isset($_POST['first'])) {
$num[] = $_POST['first'];
$num[] = $_POST['sec'];
$num[] = $_POST[' third '];
$num[] = $_POST[' fourth '];
$num[] = $_POST['fifth'];
}
// Conditions to get ascending order or descending order
if (isset($_POST['asc'])) {
sort($num);
echo "<label>IN ascending order: " . implode(', ', $num) . "</label>";
} else if (isset($_POST['dec'])) {
rsort($num);

1 | Page
Div:-A Web Framework & Services Roll No:-20234506062

echo "<label>In Descending order: " . implode(', ', $num) . "</label>";


}
}
?>
</div>
</body>
</html>

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

<td><input class="idata" type="email" name="pEm" id="pEm"></td>


<td class="hd">Patient Disease:</td>
<td><input class="idata" type="text" name="pDis" id="pDis"></td>
</tr>
<tr>
<td class="hd">Doctor Name:</td>
<td><input class="idata" type="text" name="dName" id="dName"></td>
<td class="hd">Doctor Contact:</td>
<td><input class="idata" type="number" name="dCon" id="dCon"></td>
</tr>
<tr>
<td class="hd">Appointment Date:</td>
<td><input class="idata" type="date" name="aDate" id="aDate"></td>
<td class="hd">Report:</td>
<td><input class="idata" type="file" name="file" id="file"></td>
</tr>
</table>
<div style="text-align: center; margin-top: 20px;">
<input class="btn" type="submit" value="SUBMIT">
<input class="btn" type="reset" value="RESET">
</div>
</form>
<div class="srh">
<input type="text">
<button class="btn">Search</button>
</div>
<div>
<table class="dtbl" border="2">
<tr>
<th>ID</th>
<th>pName</th>
<th>pGender</th>
<th>B-Group</th>
<th>DOB</th>
<th>pAddress</th>
<th>pContact</th>
<th>pEmail</th>
<th>pDisease</th>
<th>Dr. Name</th>
<th>Dr. Contact</th>
<th>Date</th>
<th>Report</th>
<th>Delete</th>
<th>Edit</th>
</tr>
<tr>
<td>1</td>

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

$con = mysqli_connect("localhost", "root", "", "demo");


$str = "SELECT * FROM `hospital` WHERE id=" . $uid;
$r = $con->query($str);
$row = $r->fetch_assoc();
$report = isset($_POST['report']) ? $_POST['report'] : $row['report'];

$str = "UPDATE `hospital` SET `pname`='$pname', `pgender`='$pgender',


`bgroup`='$bgroup', `dob`='$dob', `paddress`='$paddress', `pcon`='$pcon',
`pemail`='$pemail', `pdis`='$pdis', `drname`='$drname', `drcon`='$drcon',
`apdate`='$apdate', `report`='$report' WHERE id=" . $uid;

if (
$pname != "" && $bgroup != "" &&
$pgender != "" && $dob != "" &&
$paddress != "" && $pcon != "" &&
$pemail != "" && $pdis != "" &&
$drname != "" && $drcon != "" &&
$apdate != "" && $report != ""
){
$res = $con->query($str);

if ($res) {
header("Location: journal2.php");
}
}
}
?>

<form action="journal2.php" method="POST">


<h1>Patient Details Form</h1>
<input type="hidden" name="uid" value="<?php echo (isset($_GET['uid']) &&
$_GET['uid'] != "") ? $_GET['uid'] : ''; ?>">
<!-- Add your form fields here -->
</form>

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


<div class="srh">

8 | Page
Div:-A Web Framework & Services Roll No:-20234506062

<input type="text" name="searchText">


<input type="submit" value="Search" name="search">
</div>
</form>

<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'];

// Replace these with your database connection code


$conn = new mysqli("localhost", "root", "", "hospital");

// Check the database connection


if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Prepare and execute the SQL query


$sql = "SELECT * FROM `users` WHERE `id`='$user_id'";
$result = $conn->query($sql);

// Check if there are results


if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc()) {
$email = $row['email'];
$password = $row['password'];
$id = $row['id'];
}
}

// Close the database connection


$conn->close();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">

11 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062

<meta http-equiv="X-UA-Compatible" content="IE=edge">


<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css/style.css">
<script>
function validateForm() {
let x = document.forms["myForm"]["email"].value;
let y = document.forms["myForm"]["password"].value;

if (x == "" && y == "") {


alert("Please enter email and password");
return false;
} else if (x == "") {
alert("Please enter email");
return false;
} else if (y == "") {
alert("Please enter password");
return false;
} else {
if (x == "<?php echo $email; ?>" && y == "<?php echo $password; ?>") {
return true;
} else {
alert("Please check your email and password");
return false;
}
}
}

var loadFile = function (event) {


var image = document.getElementById('output');
image.src = URL.createObjectURL(event.target.files[0]);
};
</script>
</head>
<body>
<div class="container">
<div class="title">Sign in</div>
<div class="content">
<form method="POST" name="myForm" onsubmit="return validateForm()"
action="feedback.php">
<div class="user-details">
<div class="input-box">
<span class="details">Email</span>
<input type="text" name="email" placeholder="Enter your email" required>
</div>
<div class="input-box">
<span class="details">Password</span>

12 | P a g e
Div:-A Web Framework & Services Roll No:-20234506062

<input type="text" name="password" placeholder="Enter your password" required>


</div>
</div>
<div class="button">
<input type="submit" value="Sign in" name="submit">
</div>
</form>
</div>
<div><a href="patient_registration.php">Register</a></div>
</div>
</body>
</html>

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

# Path to the file that stores the visitor count


count_file = 'visitor_count.txt'

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

echo "<p>Visitor Count: $visitor_count</p>";


?>
</body>

</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 ($data !== false) {


$data = explode(" ", $data);
$con = mysqli_connect($data[0], $data[1], $data[2], $data[3]);

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

$query = "SELECT * FROM image WHERE album = $albumId";


$res = $con->query($query);
$img = "";
if ($res && $row = mysqli_fetch_row($res)) {
$img = htmlspecialchars($row[1]);
}
?>
<div class="imageback">
<a href="album.php?album=<?php echo $albumId; ?>" style="font-size: 0em"
name="data">
<img class="image" src="<?php echo $img; ?>" alt="no image" width="100"
srcset="">
<p class="txt"><?php echo $albumName; ?></p>
</a>
</div>
<?php
}
}
?>
</div>
</form>
</body>
</html>

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());
}

if (isset($_FILES['pic']) && $_FILES['pic']['name'] != "") {


$img_name = $_FILES['pic']['name'];
$img_path = $_FILES['pic']['tmp_name'];
$folder = "img/" . $img_name;
move_uploaded_file($img_path, "img/" . $img_name);

$query = "INSERT INTO image (pic, album) VALUES ('$folder', $id)";


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

header("Location: album.php?album=$id");
exit;
}

$str = "SELECT * FROM image WHERE album=$id";


$res = $con->query($str);
$data = mysqli_fetch_all($res);
?>
<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">
<link rel="stylesheet" href="album.css">

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());
}

$str = "SELECT * FROM image WHERE id=" . $id;


$res = $con->query($str);
$data = mysqli_fetch_row($res);

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">&lt;&lt;</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">&#8617;</button>
<button class="bp" name="p" type="submit">&#8618;</button>
</div>
</form>
</body>
</html>

Output:-

23 | P a g e

You might also like