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

mid

The document outlines a series of tasks related to file handling and form submission in PHP, including creating functions for file operations such as create, read, append, delete, and truncate. It also provides an HTML form for student data input, along with PHP code to handle form submissions, display data, and store records in a text file. Additionally, it includes an example of inline CSS for a div tag and mentions jQuery for animations.

Uploaded by

emankulsoom07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

mid

The document outlines a series of tasks related to file handling and form submission in PHP, including creating functions for file operations such as create, read, append, delete, and truncate. It also provides an HTML form for student data input, along with PHP code to handle form submissions, display data, and store records in a text file. Additionally, it includes an example of inline CSS for a div tag and mentions jQuery for animations.

Uploaded by

emankulsoom07
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

**Q1. Design and develop an online interface for file handling in PHP.

(10 Marks)**

You are required to create an interface in PHP for handling files (Create, Open, Read, Write,
Append, Close, Delete, Truncate) using file handling functions.

**PHP File Handling Code**:


```php

<?php

// Function to create and write to a file

function createFile($filename, $content) {

$file = fopen($filename, "w");

fwrite($file, $content);

fclose($file);
}

// Function to read a file

function readFileContent($filename) {

$file = fopen($filename, "r");

echo fread($file, filesize($filename));

fclose($file);
}

// Function to append to a file

function appendFile($filename, $content) {

$file = fopen($filename, "a");


fwrite($file, $content);
fclose($file);

// Function to delete a file


function deleteFile($filename) {

if (file_exists($filename)) {

unlink($filename);

echo "File deleted successfully.";

} else {
echo "File does not exist.";

// Function to truncate (clear) a file

function truncateFile($filename) {

$file = fopen($filename, "w");

fclose($file); // File content cleared

?>
```

This code snippet provides basic functions to **create**, **read**, **append**, **delete**, and
**truncate** files in PHP.

---

**Q2. Write down the HTML and PHP code to design and develop a front-end interface with
specific fields. (5 Marks)**
**HTML Form**:
```html

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

<label>Student Name:</label>
<input type="text" name="student_name" maxlength="15" required><br>

<label>Father Name:</label>

<input type="text" name="father_name" maxlength="15" required><br>

<label>Home Address:</label>

<input type="text" name="home_address" maxlength="20"><br>

<label>Sex:</label>

<input type="radio" name="sex" value="Male" checked> Male

<input type="radio" name="sex" value="Female"> Female<br>

<label>Phone No:</label>

<input type="text" name="phone" maxlength="15" required><br>

<input type="submit" value="Submit">

<input type="reset" value="Reset"><br>

<input type="submit" name="search" value="Search by Student Name">

<input type="submit" name="update" value="Update by Phone Number">

<input type="submit" name="show_all" value="Show All Records">

</form>
```
**PHP (student.php) Code**:
```php

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {

$student_name = $_POST['student_name'];

$father_name = $_POST['father_name'];

$home_address = $_POST['home_address'];

$sex = $_POST['sex'];
$phone = $_POST['phone'];

// Handle form submission for insert


if (isset($_POST['submit'])) {

// Save student record into a text file

$file = fopen("students.txt", "a");

fwrite($file, "$student_name|$father_name|$home_address|$sex|$phone\n");

fclose($file);

echo "Record inserted successfully!";

// Handle search by student name

if (isset($_POST['search'])) {

// Code to search by student name in 'students.txt'

// Handle update by phone number


if (isset($_POST['update'])) {
// Code to update record by phone number in 'students.txt'

// Handle show all records


if (isset($_POST['show_all'])) {

// Code to display all records from 'students.txt'

?>
```

This PHP script saves student records in a text file and handles searches, updates, and displaying
all records.

---

**Q3. Display the form data on submission and store values in a text file. (5 Marks)**

This question builds on **Q2**, requiring you to print the submitted form data and store it in a
text file.

**HTML Form Submission**:

When the user submits the form, the following PHP code will print all values:

**PHP Code (student.php)**:


```php

if (isset($_POST['submit'])) {

echo "Student Name: $student_name<br>";


echo "Father Name: $father_name<br>";
echo "Home Address: $home_address<br>";

echo "Sex: $sex<br>";

echo "Phone No: $phone<br>";

}
```

This PHP code will display all the submitted form values on the web page and also store them in
a text file as in **Q2**.

---
**Q4. Write inline CSS code to modify three attributes of the div tag. Write code for
animations using jQuery. (5 Marks)**

**Inline CSS Example for Div Tag**:


```html

<div style="background-color: lightblue; border: 2px solid black; padding: 10px;">

Welcome to UET Taxila Website!


</div>

```

This code modifies the **background color**, **border**, and **padding** of the `div` tag.

You might also like