mid
mid
(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
fwrite($file, $content);
fclose($file);
}
function readFileContent($filename) {
fclose($file);
}
if (file_exists($filename)) {
unlink($filename);
} else {
echo "File does not exist.";
function truncateFile($filename) {
?>
```
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
<label>Student Name:</label>
<input type="text" name="student_name" maxlength="15" required><br>
<label>Father Name:</label>
<label>Home Address:</label>
<label>Sex:</label>
<label>Phone No:</label>
</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'];
fwrite($file, "$student_name|$father_name|$home_address|$sex|$phone\n");
fclose($file);
if (isset($_POST['search'])) {
?>
```
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.
When the user submits the form, the following PHP code will print all values:
if (isset($_POST['submit'])) {
}
```
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)**
```
This code modifies the **background color**, **border**, and **padding** of the `div` tag.