Assignment_3
Assignment_3
Languages
(Faisalabad Campus)
Subject Web
Assignment 03
Roll No FSD-FL-114
Question # 1:
Create a form fields such as name, price and description. Use placeholders to
guide the required data format. Implement an empty field check on form
submission. Upon clicking, transfer the required enter data to a separate page
named “Check.php” On the receiving page validate the existence of data and
apply regular expression checks. Additionally, specify the method employed for
sending data from this form.
Form Code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Form Submission</title>
</head>
<body>
<form action="Check.php" method="POST" onsubmit="return validateForm()">
<input type="text" name="name" placeholder="Enter name" id="name"><br>
<input type="text" name="price" placeholder="Enter price (e.g., 100.50)"
id="price"><br>
<textarea name="description" placeholder="Enter description"
id="description"></textarea><br>
<button type="submit">Submit</button>
</form>
<script>
function validateForm() {
const name = document.getElementById("name").value.trim();
const price = document.getElementById("price").value.trim();
const description =
document.getElementById("description").value.trim();
Output:
Question # 2:
Create a database of ABC in phpMyAdmin. Consider three tables User,
product, and Order. You can add table attributes accordingly. But it is
necessary to add primary and foreign keys to each table. Write a code for
webpage to connect with your database. Secondly, includes your database
connectivity file to select records from the order table and display them on
a web page table for view.
Database Structure:
CREATE DATABASE ABC;
USE ABC;
Display Records:
<?php
include 'db_connect.php';
if ($result->num_rows > 0) {
echo "<table border='1'>
<tr>
<th>Order ID</th>
<th>User Name</th>
<th>Product Name</th>
<th>Order Date</th>
</tr>";
while($row = $result->fetch_assoc()) {
echo "<tr>
<td>{$row['order_id']}</td>
<td>{$row['user_name']}</td>
<td>{$row['product_name']}</td>
<td>{$row['order_date']}</td>
</tr>";
}
echo "</table>";
} else {
echo "No orders found!";
}
$conn->close();
?>
Output:
Question # 3:
What do you know about associative array in PHP/JavaScript to store and
manipulate data. Using an example of an associative array to demonstrate
how to access, modify and loop through its elements. Also explain the
practical scenario where associative array would be particularly useful in
PHP/JavaScript programming.
$student = [
"name" => "John Doe",
"age" => 20,
"major" => "Computer Science"
];
// Access
echo "Name: " . $student["name"] . "<br>";
// Modify
$student["age"] = 21;
// Loop
foreach ($student as $key => $value) {
echo "$key: $value<br>";
}
const student = {
name: "John Doe",
age: 21,
major: "Computer Science"
};
// Access
console.log("Name:", student.name);
// Modify
student.age = 26;
// Loop
for (const key in student) {
console.log(`${key}: ${student[key]}`);
}
Output:
Question # 4:
What do you know about the following given below and explain
with the help of an examples?
Cookies Management
File Handling
Ajax
Pagination
1. Cookies Management:
Output:
2. File Handling:
Output:
3. AJAX:
Output:
Output: