Unit 1 of 1 · BCA Sem 3

Unit 1: PHP application development

Web Programming-I Laboratory notes · PTU syllabus (UGDSE302)

3 min read4 topics8 exam questions
On this page
  1. Unit summary
  2. Setting up the environment
  3. Forms, files and sessions
  4. MySQL registration and displaying records
  5. Mini project, Git and deployment
  6. Key terms
  7. Quick revision
  8. Important questions

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
1

Topic 1

Setting up the environment

PHP runs on a web server, not in the browser alone. For practice, a package such as XAMPP installs the Apache server, PHP and MySQL on your own computer.

ProcessLocal PHP setup
  1. 1Install XAMPP

    Apache + MySQL + PHP

  2. 2Start Apache and MySQL
  3. 3Put files in htdocs

    C:/xampp/htdocs/project

  4. 4Open localhost/project in the browser
  5. 5Create the database in phpMyAdmin

    localhost/phpmyadmin

Example

Your first PHP page: start Apache in the XAMPP control panel. Save a file hello.php in C:/xampp/htdocs/lab/ containing <?php echo "Hello, SBS"; ?>. Open http://localhost/lab/hello.php in the browser. Opening the file by double-clicking will not work, because the server must run the PHP code.

2

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");

Example

GET and POST: a search form using GET shows search.php?q=php in the address bar and can be bookmarked. A login form uses POST, so the password is not shown in the URL. Read them with $_GET["q"] and $_POST["password"].

3

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.

Example

A safe insert: $stmt = $conn->prepare("INSERT INTO student (name, email) VALUES (?, ?)"); $stmt->bind_param("ss", $name, $email); $stmt->execute(); The values are sent separately from the SQL, which prevents SQL injection.

Exam tip

Never put form input directly into an SQL string. Use prepared statements.

4

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 push to 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?"

Example

A Git workflow: git init, git add ., git commit -m "First version", then push to GitHub and deploy on a free hosting service, recording the live URL in the project report.

Exam tip

Commit small, meaningful changes with clear messages.

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

  1. Q1.What is XAMPP?
  2. Q2.How do you protect a page so only logged-in users can see it?
  3. Q3.Why should passwords be hashed?
  4. Q4.What does fetch_assoc() return?
  5. Q5.Name three basic Git commands.

Long-answer questions

  1. Q1.Build a session-based login system in PHP and explain each step.
  2. Q2.Create a student registration form that stores data in MySQL and displays all records in a table.
  3. 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.

WhatsApp us