You are on page 1of 9

Q3.

Design a form for the Patient Satisfaction Survey for a particular hospital having the following fields:
• Patient's name
• Patient's File number (Issued by the hospital)
• Which Unit of the hospital the patient was admitted Select V (Surgery, Medicine, etc.)
• Are you satisfied with overall treatment : Very Satisfied Satisfied Not Satisfied
• Are you satisfied with medical facilities in the hospital : Very Satisfied Satisfied Not Satisfied
• Overall Comments 15
 Submit
 Reset

** CODE **

<?php
// Initialize variables for error handling
$nameErr = $fileNumberErr = $unitErr = $treatmentSatisfactionErr = $facilitiesSatisfactionErr = "";
$successMessage = false;
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Validate and sanitize input
$name = test_input($_POST["name"]);
$fileNumber = test_input($_POST["fileNumber"]);
$unit = test_input($_POST["unit"]);
$treatmentSatisfaction = test_input($_POST["treatmentSatisfaction"]);
$facilitiesSatisfaction = test_input($_POST["facilitiesSatisfaction"]);
$comments = test_input($_POST["comments"]);

// Database connection settings (replace with your database details)


$host = "localhost";
$username = "root";
$password = "";
$database = "hospital";

// Create a database connection


$conn = new mysqli($host, $username, $password, $database);

// Check for database connection errors


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

// Insert data into the database


$sql = "INSERT INTO patient_survey (name, fileNumber, unit, treatmentSatisfaction,
facilitiesSatisfaction, comments)
VALUES ('$name', '$fileNumber', '$unit', '$treatmentSatisfaction', '$facilitiesSatisfaction',
'$comments')";
if ($conn->query($sql) === TRUE) {
// Data inserted successfully
$successMessage = "Thank you for completing the survey!";
} else {
$errorMessage = "Error: " . $sql . "<br>" . $conn->error;
}

// Close the database connection


$conn->close();
}

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Patient Satisfaction Survey</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f7f7f7;
}

h1 {
text-align: center;
color: #333;
}
.message {
max-width: 500px;
margin: 0 auto;
background-color: #D4ADFC;
margin-bottom : 10px;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}

.message p{
color : #000;
}

.container {
max-width: 500px;
margin: 0 auto;
background-color: #fff;
padding: 20px;
border-radius: 5px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
margin-bottom : 10px;
}

label {
display: block;
font-weight: bold;
margin-top: 10px;
}

input[type="text"],
select,
textarea {
width: 100%;
padding: 10px;
margin-top: 5px;
margin-bottom: 10px;
border: 1px solid #ccc;
border-radius: 4px;
}

input[type="radio"] {
margin-right: 5px;
}

.error {
color: #ff0000;
font-size: 14px;
}

.submit-button {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}

.reset-button {
background-color: #f44336;
color: white;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
}
</style>
</head>
<body>
<h1>Patient Satisfaction Survey</h1>
<?php if (isset($successMessage) && !empty($successMessage)) { ?>
<div class="message">
<p><?php echo $successMessage; ?></p>
</div>
<?php } ?>
<div class="container">

<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">


<label for="name">Patient's name:</label>
<input type="text" name="name" required>

<label for="fileNumber">Patient's File number:</label>


<input type="text" name="fileNumber" required>

<label for="unit">Unit of the hospital:</label>


<select name="unit" required>
<option value="Surgery">Surgery</option>
<option value="Medicine">Medicine</option>
<!-- Add more unit options here -->
</select>

<label for="treatmentSatisfaction">Satisfaction with treatment:</label><br>


<input type="radio" name="treatmentSatisfaction" value="Very Satisfied"> Very Satisfied
<input type="radio" name="treatmentSatisfaction" value="Satisfied"> Satisfied
<input type="radio" name="treatmentSatisfaction" value="Not Satisfied"> Not Satisfied

<label for="facilitiesSatisfaction">Satisfaction with medical facilities:</label><br>


<input type="radio" name="facilitiesSatisfaction" value="Very Satisfied"> Very Satisfied
<input type="radio" name="facilitiesSatisfaction" value="Satisfied"> Satisfied
<input type="radio" name="facilitiesSatisfaction" value="Not Satisfied"> Not Satisfied

<label for="comments">Overall Comments:</label><br>


<textarea name="comments" rows="4" cols="50"></textarea>

<input type="submit" class="submit-button" value="Submit">


<input type="button" class="reset-button" value="Reset" onclick="resetForm()">
</form>
</div>
</body>
</html>
** OUTPUT **
Q4. Create an HTML web page, as shown below. The cookie1 and cookie2 will be set on pressing Set Cookie1or Set
Cookie2 button and the stored cookie value will be displayed on pressing Get Cookie1 or Get Cookie2 button
respectively. On the other hand selectively cookie can be deleted by pressing Delete Cookie1 or Delete Cookie2 button.
Display all cookies button will show all the stored cookies.

** CODE **
<!DOCTYPE html>
<html>
<head>
<title>Cookies Example</title>
</head>
<body>
<h1>Cookie Management</h1>

<button onclick="setCookie('cookie1')">Set Cookie1</button>


<button onclick="setCookie('cookie2')">Set Cookie2</button><br><br>

<button onclick="getCookie('cookie1')">Get Cookie1</button>


<button onclick="getCookie('cookie2')">Get Cookie2</button><br><br>

<button onclick="deleteCookie('cookie1')">Delete Cookie1</button>


<button onclick="deleteCookie('cookie2')">Delete Cookie2</button><br><br>

<button onclick="displayAllCookies()">Display All Cookies</button><br><br>

<p id="cookieDisplay"></p>

<script>
function setCookie(cookieName) {
var cookieValue = prompt('Enter the value for ' + cookieName + ':');
document.cookie = cookieName + '=' + cookieValue;
}

function getCookie(cookieName) {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i].trim();
if (cookie.startsWith(cookieName + '=')) {
var cookieValue = cookie.substring(cookieName.length + 1);
alert(cookieName + ' = ' + cookieValue);
return;
}
}
alert(cookieName + ' not found');
}

function deleteCookie(cookieName) {
document.cookie = cookieName + '=; expires=Thu, 01 Jan 1970 00:00:00 UTC;';
alert(cookieName + ' deleted');
}

function displayAllCookies() {
var cookies = document.cookie.split(';');
var cookieDisplayText = 'All Cookies:' + '\n';
for (var i = 0; i < cookies.length; i++) {
cookieDisplayText += cookies[i].trim() + '\n';
}
document.getElementById('cookieDisplay').textContent = cookieDisplayText;
}
</script>
</body>
</html>

** OUTPUT **
- Set Cookies
- Stored Cookies

- Get Cookies

- Displaying All Cookies

- Deleting Cookies

You might also like