Unit 1 of 3 · BCA Sem 3

Unit 1: Introduction to PHP programming

Web Programming-I notes · PTU syllabus (UGDSE301)

3 min read4 topics8 exam questions
On this page
  1. Unit summary
  2. Server-side scripting
  3. PHP syntax, variables and data types
  4. Control structures and functions
  5. Handling HTML forms
  6. Key terms
  7. Quick revision
  8. Important questions

Unit summary

HTML pages are static; real websites need code that runs on the server — to process forms, talk to databases and build pages dynamically. PHP is one of the most widely used server-side languages. This unit introduces server-side scripting and the basics of PHP: syntax, variables, constants, data types, operators, control structures, functions, and handling HTML forms.

After this unit you can

  • Explain server-side scripting and how PHP works with a web server
  • Use PHP variables, constants, data types and operators
  • Write PHP control structures and functions
  • Process HTML form data with GET and POST

PTU syllabus topics

  • Server-side scripting overview
  • PHP syntax
  • variables
  • constants
  • data types
  • expressions
  • operators
  • control structures (if, else, switch, loops)
  • functions
  • handling HTML forms with GET and POST
  • embedding PHP into HTML
ProcessHow a PHP page is served
  1. 1Request

    Browser asks for page.php

  2. 2Execute

    Server runs the PHP code

  3. 3Generate

    PHP outputs HTML

  4. 4Respond

    Browser receives plain HTML

1

Topic 1

Server-side scripting

ComparisonClient-side vs server-side scripting
Client-side (JavaScript)
Server-side (PHP)

Runs on

The browser

The web server

Can access database?

No (directly)

Yes

Code visible to user?

Yes

No — only the HTML output is sent

Uses

Validation, interactivity

Logins, database access, dynamic pages

ProcessHow a PHP page is served
  1. 1Browser requests page.php
  2. 2Web server (Apache) passes it to the PHP engine
  3. 3PHP runs

    May query MySQL

  4. 4Output HTML is sent back
  5. 5Browser displays it
2

Topic 2

PHP syntax, variables and data types

PHP code sits inside <?php ... ?> tags and statements end with semicolons.

php<?php
$name = "Ana";             // string
$age = 19;                 // integer
$cgpa = 8.6;               // float
$isEnrolled = true;        // boolean
define("COLLEGE", "SBS");  // constant
echo "Hello $name from " . COLLEGE;   // . joins strings
?>
  • Variables start with $, are case-sensitive, and need no type declaration (PHP is loosely typed).
  • Data types: string, integer, float, boolean, array, object, NULL and resource.
  • Operators: arithmetic (+ − × / % **), assignment (=, +=), comparison (==, ===, !=, <, >), logical (&&, ||, !) and string concatenation (.).
3

Topic 3

Control structures and functions

php<?php
$marks = 72;
if ($marks >= 75) echo "Distinction";
elseif ($marks >= 60) echo "First division";
else echo "Pass";

for ($i = 1; $i <= 5; $i++) echo $i;
foreach (["BCA", "BBA"] as $course) echo $course;

function area($l, $b = 1) {   // default parameter
    return $l * $b;
}
echo area(5, 4);              // 20
?>

PHP also has while, do…while and switch.

4

Topic 4

Handling HTML forms

html<form action="welcome.php" method="post">
  Name: <input type="text" name="uname">
  <input type="submit">
</form>
php<?php
$name = htmlspecialchars($_POST["uname"]);   // prevents script injection
echo "Welcome, $name";
?>
  • $_GET reads data sent in the URL; $_POST reads data sent in the request body; $_REQUEST reads both.

Exam tip

Always validate and sanitise form input on the server (with htmlspecialchars, filter_var and prepared statements) — never trust user input.

Key terms

Server-side scripting
Code executed on the web server before the page is sent
PHP
A server-side scripting language for dynamic web pages
Superglobal
Built-in arrays like $_GET and $_POST available everywhere
Loosely typed
Variables don't need a declared type
htmlspecialchars
Converts special characters to prevent injection

Quick revision

  • PHP runs on the server; only HTML reaches the browser.
  • Variables start with $; constants with define().
  • . concatenates strings; === checks value and type.
  • $_GET for URL data, $_POST for form-body data.

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.Differentiate between client-side and server-side scripting.
  2. Q2.How are variables declared in PHP?
  3. Q3.How do you define a constant in PHP?
  4. Q4.Differentiate between $_GET and $_POST.
  5. Q5.What is the use of htmlspecialchars?

Long-answer questions

  1. Q1.Explain how a PHP page is processed by a web server.
  2. Q2.Explain PHP data types, operators and control structures with examples.
  3. Q3.Write a PHP program to process a registration form using POST.

Stuck on this unit?

Message SBS on WhatsApp for help with Web Programming-I, or to ask about studying BCA at Synetic.

WhatsApp us