Unit 1: PHP application development
Web Programming-I Laboratory notes · PTU syllabus (UGDSE302)
On this page
Unit summary
This lab builds working PHP applications step by step — form handling, loops and conditions, a feedback form, a file-backed contact form, a session login, MySQL registration, displaying records in tables, and a deployed mini project — using XAMPP/WAMP/LAMP, phpMyAdmin and Git.
After this unit you can
- Set up a local server and database with XAMPP and phpMyAdmin
- Build forms that store data in files and MySQL
- Implement a session-based login system
- Build, version and deploy a mini project
PTU syllabus topics
- PHP scripts for form input
- conditions and loops
- GET/POST feedback forms
- text-file-backed contact forms
- session-based login system
- MySQL-backed user registration
- mini project (blog system, inventory manager or task tracker)
- deployment on a local server or free hosting platform
- displaying database data in table format using PHP
- using XAMPP/WAMP/LAMP
- phpMyAdmin and Git/GitHub basics
- 1Registration form
Collect and validate input
- 2Store user
Insert into MySQL with a hashed password
- 3Login form
Check credentials
- 4Start session
Remember the logged-in user
- 5Logout
Destroy the session
Topic 1
Setting up the environment
- 1Install XAMPP
Apache + MySQL + PHP
- 2Start Apache and MySQL
- 3Put files in htdocs
C:/xampp/htdocs/project
- 4Open localhost/project in the browser
- 5Create the database in phpMyAdmin
localhost/phpmyadmin
Topic 2
Forms, files and sessions
- GET/POST feedback form: read with
$_POST, validate, and display a thank-you message. - Contact form saved to a text file:
file_put_contents("contacts.txt", "$name,$email\n", FILE_APPEND); - Session login:
php<?php
session_start();
if ($_POST["user"] === "admin" && password_verify($_POST["pwd"], $hash)) {
$_SESSION["user"] = "admin";
header("Location: dashboard.php");
} else {
echo "Invalid login";
}
?>Protect each private page with if (!isset($_SESSION["user"])) header("Location: login.php");
Topic 3
MySQL registration and displaying records
php<?php
$conn = new mysqli("localhost", "root", "", "college");
$res = $conn->query("SELECT roll, name, course FROM student");
echo "<table border='1'><tr><th>Roll</th><th>Name</th><th>Course</th></tr>";
while ($row = $res->fetch_assoc()) {
echo "<tr><td>{$row['roll']}</td><td>{$row['name']}</td><td>{$row['course']}</td></tr>";
}
echo "</table>";
?>Store passwords with password_hash(), never as plain text.
Topic 4
Mini project, Git and deployment
Choose a blog system, inventory manager or task tracker with CRUD features, login and a clean layout.
- Git basics:
git init,git add .,git commit -m "message",git pushto GitHub. - Deployment: upload files and the exported database to free hosting (for example InfinityFree) or demonstrate on localhost.
Exam tip
Viva favourites: "What is the difference between include and require?" (require stops on error), "Why hash passwords?", and "How do sessions work?"
Key terms
- XAMPP
- A package with Apache, MySQL and PHP for local development
- phpMyAdmin
- A web tool for managing MySQL databases
- password_hash
- Securely hashes a password
- Git
- A version control system tracking code changes
Quick revision
- Files go in htdocs; open via localhost.
- FILE_APPEND adds to a file without overwriting.
- Check $_SESSION on every protected page.
- Hash passwords; use prepared statements.
Important exam questions
Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).
Short-answer questions
- Q1.What is XAMPP?
- Q2.How do you protect a page so only logged-in users can see it?
- Q3.Why should passwords be hashed?
- Q4.What does fetch_assoc() return?
- Q5.Name three basic Git commands.
Long-answer questions
- Q1.Build a session-based login system in PHP and explain each step.
- Q2.Create a student registration form that stores data in MySQL and displays all records in a table.
- Q3.Describe the mini project you built, its features and how it was deployed.
Stuck on this unit?
Message SBS on WhatsApp for help with Web Programming-I Laboratory, or to ask about studying BCA at Synetic.
