Dynamic Web Pages with PHP and MySQL – Grade 13 A/L ICT Notes 10.7

© 2026 schoolict.net (Ruwan Mangala Suraweera)

10.7 Dynamic Web Pages with PHP and MySQLPHP සහ MySQL සමඟ ගතික වෙබ් පිටු

Grade 13 A/L ICT · Lesson 1013 ශ්‍රේණිය A/L ICT · පාඩම 10

Prints all tabs in the language you are reading. Use “Save as PDF” in the print window to keep a copy.ඔබ කියවන භාෂාවෙන් සියලු tabs මුද්‍රණය වේ. පිටපතක් තියාගන්න print window එකේ “Save as PDF” තෝරන්න.
🎬Video coming soon in this language. Switch language to watch the other video.මේ භාෂාවෙන් වීඩියෝව ඉක්මනින් එනවා. අනෙක් වීඩියෝව බලන්න භාෂාව මාරු කරන්න.

In this videoමේ වීඩියෝවේ

  • Dynamic pages are built on the server.ගතික පිටු සේවාදායකයේ සාදයි.
  • PHP sits in and echoes HTML.PHP තුළ HTML echo කරයි.
  • Variables, arrays, control structures, functions.විචල්‍ය, අරා, පාලනය, ශ්‍රිත.
  • Forms send data by GET or POST.පෝරම GET හෝ POST.
  • PHP saves and retrieves MySQL data.PHP MySQL දත්ත සුරකියි/ලබා ගනී.
Static web pageDynamic web pagePHPServer-side scriptVariableArrayAssociative array

Notesසටහන්

Syllabus 10.7. A static page shows the same HTML to everyone; a dynamic page is built by the server each time, often from a database. PHP code is embedded in HTML between , runs on the web server and sends only HTML to the browser. You use variables, arrays, control structures and functions, collect input with forms and save or retrieve data in a MySQL database.විෂය නිර්දේශය 10.7. ස්ථිතික පිටුවක් සැමට එකම HTML පෙන්වයි; ගතික පිටුවක් සෑම වරම සේවාදායකය මගින්, බොහෝ විට දත්ත සමුදායකින් ගොඩනගයි. PHP කේතය අතර HTML තුළ කාවද්දා, වෙබ් සේවාදායකයේ ධාවනය වී බ්‍රව්සරයට HTML පමණක් යවයි. විචල්‍ය, අරා, පාලන ව්‍යුහ සහ ශ්‍රිත භාවිත කර, පෝරම මගින් ආදානය ලබා MySQL දත්ත සමුදායක සුරකියි හෝ ලබා ගනී.

1. How PHP works1. PHP ක්‍රියා කරන ආකාරය

How a dynamic PHP page is builtBrowserform / linkWeb server(Apache)PHP engineruns the codeMySQLdatabase12345 HTML61 request (GET/POST) · 2 run .php file · 3 SQL query · 4 rows back · 5 HTML · 6 page shownThe browser never sees PHP code – only the HTML that PHP prints with echo.
Browser, server, PHP and MySQLබ්‍රව්සරය, සේවාදායකය, PHP සහ MySQL

2. PHP basics2. PHP මූලික

🐘 PHP: Variables, arrays, control structures and a functionවිචල්‍ය, අරා, පාලන ව්‍යුහ සහ ශ්‍රිතයක්
>>
= 75) {
        return "A";
    } elseif ($mark >= 50) {
        return "C";
    } else {
        return "F";
    }
}

echo ">" . $school . ">";
echo ">Total: $total, Average: " . round($avg, 1) . ">";
for ($i = 0; $i < count($marks); $i++) {
    echo ">" . $marks[$i] . " = " . grade($marks[$i]) . ">";
}
$student = array("name" => "Nimal", "stream" => "Tech");   // associative array
echo ">" . $student["name"] . " (" . $student["stream"] . ")>";
?>
>>

▶ HTML sent to the browserබ්‍රව්සරයට යවන HTML


Green Valley

Total: 211, Average: 70.3

78 = A

45 = F

88 = A

Nimal (Tech)

▶ What the browser showsබ්‍රව්සරය පෙන්වන දේ

Elementමූලද්‍රව්‍යයUseභාවිතය
One line of text; name is the key PHP reads, value the default textපෙළ පේළියක්; name PHP කියවන key, value පෙරනිමි පෙළ
type=”password”type=”password”Text shown as dotsතිත් ලෙස පෙන්වන පෙළ
type=”radio”type=”radio”Choose one of a group with the same nameඑකම name සහිත කණ්ඩායමෙන් එකක්
type=”checkbox”type=”checkbox”Tick any number of optionsඕනෑම ගණනක් තෝරා ගැනීම
Drop-down selection listDrop-down ලැයිස්තුව
type=”submit” / type=”reset”type=”submit” / type=”reset”Send the form / clear itපෝරමය යැවීම / හිස් කිරීම
action=”save.php” method=”post”action=”save.php” method=”post”Where and how the data is sentදත්ත යවන තැන සහ ආකාරය
Groups related fields with a captionසම්බන්ධ ක්ෂේත්‍ර කණ්ඩායම් කිරීම
GET and POSTGETdata in the URL: hello.php?name=Kamalavisible, can be bookmarkedlimited length · for searchesPOSTdata in the request bodynot shown in the URLlarge data · passwords, savingPHP reads them with $_GET[“name”] and $_POST[“name”].
GET and POST methodsGET සහ POST ක්‍රම
🐘 PHP: Reading a value sent with GETGET මගින් යැවූ අගයක් කියවීම
>Hello, " . htmlspecialchars($name) . "!>";
?>

▶ HTML sent to the browserබ්‍රව්සරයට යවන HTML (GET name=Kamala)

Hello, Kamala!

▶ What the browser showsබ්‍රව්සරය පෙන්වන දේ

🐘 PHP: list.php – retrieving data into an HTML tablelist.php – දත්ත HTML වගුවකට ලබා ගැනීම
query("SELECT id, name, mark FROM student WHERE stream = 'Tech' ORDER BY mark DESC");
echo " border=\"1\">";
echo ">>ID>>Name>>Mark>>";
foreach ($result as $row) {
    echo ">>" . $row["id"] . ">>" . $row["name"] . ">>" . $row["mark"] . ">>";
}
echo ">";
?>

▶ HTML sent to the browserබ්‍රව්සරයට යවන HTML

IDNameMark
3Sunil88
1Nimal78

▶ What the browser showsබ්‍රව්සරය පෙන්වන දේ

🐘 PHP: edit.php – setting form values from retrieved dataedit.php – ලබා ගත් දත්තවලින් පෝරම අගයන් සැකසීම
prepare("SELECT * FROM student WHERE id = ?");
$stmt->execute(array($_GET["id"]));
$row = $stmt->fetch();
?>
 action="update.php" method="post">
  ">
  Name: ">
  Mark: ">
   type="submit" value="Update">
>

▶ HTML sent to the browserබ්‍රව්සරයට යවන HTML (GET id=2)

Name: Mark:

▶ What the browser showsබ්‍රව්සරය පෙන්වන දේ

🧮 Worked exampleවිසඳූ උදාහරණය What does each database program print, and why?එක් එක් දත්ත සමුදා වැඩසටහන මුද්‍රණය කරන්නේ කුමක්ද, ඇයි?
save.php receives name=Amali by POST, runs a prepared INSERT and prints “Saved 1 record” – the table now has 4 students. list.php selects stream Tech ordered by mark DESC, so Sunil 88 comes before Nimal 78. edit.php reads id=2 from the URL and puts Kamala and 45 into the value attributes, so the form opens already filled.save.php POST මගින් Amali ලබා INSERT කර “Saved 1 record” මුද්‍රණය කරයි – සිසුන් 4. list.php Tech සිසුන් mark DESC: Sunil 88, පසුව Nimal 78. edit.php id=2 කියවා Kamala සහ 45 value ගුණාංගවලට දමයි.
  • Connect: new PDO(“mysql:host=…;dbname=…”, user, password) – or mysqli_connect() in older code.සම්බන්ධ වීම: new PDO(…) – හෝ පැරණි කේතයේ mysqli_connect().
  • Use prepared statements with ? placeholders and htmlspecialchars() on output for security.ආරක්ෂාවට ? placeholders සහිත prepared statements සහ htmlspecialchars().
  • These programs were run with PHP 8; for testing, the MySQL line was swapped for an SQLite database with the same table.මෙම වැඩසටහන් PHP 8 සමඟ ධාවනය කළා; පරීක්ෂාවට MySQL පේළිය එකම වගුව සහිත SQLite එකකින් ප්‍රතිස්ථාපනය කළා.
💡 View the page source in the browser: you will see only HTML – proof that PHP ran on the server.බ්‍රව්සරයේ page source බලන්න: HTML පමණි – PHP සේවාදායකයේ ධාවනය වූ බවට සාක්ෂියකි.
🚀 Beyond the syllabus (2026 update)🚀 විෂය නිර්දේශයෙන් ඔබ්බට (2026 යාවත්කාලීනය) Not required for the exam – read for interest.විභාගයට අවශ්‍ය නැත – දැනුම සඳහා කියවන්න. In 2026 PHP 8 powers WordPress and Laravel sites; many apps also send JSON from PHP to JavaScript (fetch) instead of whole pages.2026 දී PHP 8 WordPress සහ Laravel අඩවි ධාවනය කරයි; බොහෝ යෙදුම් සම්පූර්ණ පිටු වෙනුවට PHP වෙතින් JavaScript (fetch) වෙත JSON යවයි.

Key Wordsප්‍රධාන පද

Static web pageස්ථිතික වෙබ් පිටුව
Page that shows the same content to every visitor.සෑම අමුත්තෙකුටම එකම අන්තර්ගතය.
Dynamic web pageගතික වෙබ් පිටුව
Page built by the server each time it is requested.ඉල්ලන සෑම වරම සේවාදායකය සාදන පිටුව.
PHPPHP
Server-side scripting language embedded in HTML.HTML තුළ කාවද්දන server-side භාෂාව.
Server-side scriptServer-side script
Code that runs on the web server, not the browser.බ්‍රව්සරයේ නොව සේවාදායකයේ ධාවනය වන කේතය.
Variableවිචල්‍යය
Named value in PHP starting with a dollar sign.$ ලකුණෙන් ආරම්භ වන PHP අගය.
Arrayඅරාව
Variable that holds many values by index or key.index හෝ key මගින් බොහෝ අගයන් රඳවන විචල්‍යය.
Associative arrayසංගුණක අරාව
Array that uses named keys such as name.name වැනි නම් කළ keys භාවිත කරන අරාව.
echoecho
PHP statement that outputs text or HTML.පෙළ හෝ HTML ප්‍රතිදානය කරන PHP ප්‍රකාශය.
Formපෝරමය
HTML element that collects user input.පරිශීලක ආදානය එකතු කරන HTML මූලද්‍රව්‍යය.
GET methodGET ක්‍රමය
Sends form data in the URL.URL තුළ පෝරම දත්ත යවයි.
POST methodPOST ක්‍රමය
Sends form data in the request body.request body තුළ දත්ත යවයි.
Prepared statementPrepared statement
SQL with placeholders filled safely.ආරක්ෂිතව පුරවන placeholders සහිත SQL.

Sample Q&Aආදර්ශ ප්‍රශ්න සහ පිළිතුරු

1Static vs dynamic page?ස්ථිතික සහ ගතික?

Answerපිළිතුර: Static is fixed HTML; dynamic is built by the server each time.ස්ථිර; සේවාදායකය සාදයි.

2Where does PHP run?PHP ධාවනය?

Answerපිළිතුර: On the web server.වෙබ් සේවාදායකයේ.

3Total and average in basics?එකතුව සහ සාමාන්‍යය?

Answerපිළිතුර: 211 and 70.3.211, 70.3.

4GET vs POST?GET සහ POST?

Answerපිළිතුර: GET puts data in the URL; POST hides it in the body.URL; body.

5First row of list.php?list.php පළමු පේළිය?

Answerපිළිතුර: 3, Sunil, 88.Sunil 88.

6What fills the edit form?edit පෝරමය?

Answerපිළිතුර: The row id=2 – Kamala, 45 – in value attributes.Kamala, 45.

MCQබහුවරණ ප්‍රශ්න

Choose the correct answer for each question.සෑම ප්‍රශ්නයකටම නිවැරදි පිළිතුර තෝරන්න.

Scoreලකුණු: 0 / 20

1PHP code is written betweenPHP

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D

Tags.ටැග්.

2PHP runs on theධාවනය

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A

Server-side.සේවාදායකය.

3The basics program prints AverageAverage

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B

211 ÷ 3 rounded.211 ÷ 3.

4grade(45) returnsgrade(45)

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C

Below 50.50 ට අඩු.

5Which input type shows typed text as dots?තිත්

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A

Password.Password.

6Choosing exactly one option from a group usesඑකක්

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D

Radio.Radio.

7After save.php runs, the number of students isstudents

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E

3 + 1.3 + 1.

8The first data row printed by list.php islist.php

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C

ORDER BY mark DESC.DESC.

9Which term means: “Page that shows the same content to every visitor”?“සෑම අමුත්තෙකුටම එකම අන්තර්ගතය” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B

Static web page – Page that shows the same content to every visitor.ස්ථිතික වෙබ් පිටුව – සෑම අමුත්තෙකුටම එකම අන්තර්ගතය.

10Which term means: “Page built by the server each time it is requested”?“ඉල්ලන සෑම වරම සේවාදායකය සාදන පිටුව” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C

Dynamic web page – Page built by the server each time it is requested.ගතික වෙබ් පිටුව – ඉල්ලන සෑම වරම සේවාදායකය සාදන පිටුව.

11Which term means: “Server-side scripting language embedded in HTML”?“HTML තුළ කාවද්දන server-side භාෂාව” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D

PHP – Server-side scripting language embedded in HTML.PHP – HTML තුළ කාවද්දන server-side භාෂාව.

12Which term means: “Code that runs on the web server, not the browser”?“බ්‍රව්සරයේ නොව සේවාදායකයේ ධාවනය වන කේතය” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E

Server-side script – Code that runs on the web server, not the browser.Server-side script – බ්‍රව්සරයේ නොව සේවාදායකයේ ධාවනය වන කේතය.

13Which term means: “Named value in PHP starting with a dollar sign”?“$ ලකුණෙන් ආරම්භ වන PHP අගය” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B

Variable – Named value in PHP starting with a dollar sign.විචල්‍යය – $ ලකුණෙන් ආරම්භ වන PHP අගය.

14Which term means: “Variable that holds many values by index or key”?“index හෝ key මගින් බොහෝ අගයන් රඳවන විචල්‍යය” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E

Array – Variable that holds many values by index or key.අරාව – index හෝ key මගින් බොහෝ අගයන් රඳවන විචල්‍යය.

15Which term means: “Array that uses named keys such as name”?“name වැනි නම් කළ keys භාවිත කරන අරාව” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: B

Associative array – Array that uses named keys such as name.සංගුණක අරාව – name වැනි නම් කළ keys භාවිත කරන අරාව.

16Which term means: “PHP statement that outputs text or HTML”?“පෙළ හෝ HTML ප්‍රතිදානය කරන PHP ප්‍රකාශය” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A

echo – PHP statement that outputs text or HTML.echo – පෙළ හෝ HTML ප්‍රතිදානය කරන PHP ප්‍රකාශය.

17Which term means: “HTML element that collects user input”?“පරිශීලක ආදානය එකතු කරන HTML මූලද්‍රව්‍යය” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: D

Form – HTML element that collects user input.පෝරමය – පරිශීලක ආදානය එකතු කරන HTML මූලද්‍රව්‍යය.

18Which term means: “Sends form data in the URL”?“URL තුළ පෝරම දත්ත යවයි” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: A

GET method – Sends form data in the URL.GET ක්‍රමය – URL තුළ පෝරම දත්ත යවයි.

19Which term means: “Sends form data in the request body”?“request body තුළ දත්ත යවයි” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: C

POST method – Sends form data in the request body.POST ක්‍රමය – request body තුළ දත්ත යවයි.

20Which term means: “SQL with placeholders filled safely”?“ආරක්ෂිතව පුරවන placeholders සහිත SQL” යන්නෙන් අදහස් වන පදය කුමක්ද?

✔ Correct!නිවැරදියි!✘ Not quite.වැරදියි. Correct answerනිවැරදි පිළිතුර: E

Prepared statement – SQL with placeholders filled safely.Prepared statement – ආරක්ෂිතව පුරවන placeholders සහිත SQL.

MCQ answer keyMCQ පිළිතුරු

  1. D – Tags.ටැග්.
  2. A – Server-side.සේවාදායකය.
  3. B – 211 ÷ 3 rounded.211 ÷ 3.
  4. C – Below 50.50 ට අඩු.
  5. A – Password.Password.
  6. D – Radio.Radio.
  7. E – 3 + 1.3 + 1.
  8. C – ORDER BY mark DESC.DESC.
  9. B – Static web page – Page that shows the same content to every visitor.ස්ථිතික වෙබ් පිටුව – සෑම අමුත්තෙකුටම එකම අන්තර්ගතය.
  10. C – Dynamic web page – Page built by the server each time it is requested.ගතික වෙබ් පිටුව – ඉල්ලන සෑම වරම සේවාදායකය සාදන පිටුව.
  11. D – PHP – Server-side scripting language embedded in HTML.PHP – HTML තුළ කාවද්දන server-side භාෂාව.
  12. E – Server-side script – Code that runs on the web server, not the browser.Server-side script – බ්‍රව්සරයේ නොව සේවාදායකයේ ධාවනය වන කේතය.
  13. B – Variable – Named value in PHP starting with a dollar sign.විචල්‍යය – $ ලකුණෙන් ආරම්භ වන PHP අගය.
  14. E – Array – Variable that holds many values by index or key.අරාව – index හෝ key මගින් බොහෝ අගයන් රඳවන විචල්‍යය.
  15. B – Associative array – Array that uses named keys such as name.සංගුණක අරාව – name වැනි නම් කළ keys භාවිත කරන අරාව.
  16. A – echo – PHP statement that outputs text or HTML.echo – පෙළ හෝ HTML ප්‍රතිදානය කරන PHP ප්‍රකාශය.
  17. D – Form – HTML element that collects user input.පෝරමය – පරිශීලක ආදානය එකතු කරන HTML මූලද්‍රව්‍යය.
  18. A – GET method – Sends form data in the URL.GET ක්‍රමය – URL තුළ පෝරම දත්ත යවයි.
  19. C – POST method – Sends form data in the request body.POST ක්‍රමය – request body තුළ දත්ත යවයි.
  20. E – Prepared statement – SQL with placeholders filled safely.Prepared statement – ආරක්ෂිතව පුරවන placeholders සහිත SQL.

Structured Questionsව්‍යුහගත ප්‍රශ්න

1Distinguish static and dynamic web pages.ස්ථිතික සහ ගතික. (3 marksලකුණු 3)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
Fixed vs built per request; example; database.ස්ථිර; ගතික.

2Write PHP that stores three marks in an array and prints the total and average.අරාව. (4 marksලකුණු 4)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
array; foreach; count; echo 211 and 70.3.array; foreach; echo.

3Write an HTML form with text, password, radio, checkbox, select, submit and reset.පෝරමය. (3 marksලකුණු 3)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
form action method; fieldset; each input type.form; inputs.

4Compare GET and POST.GET සහ POST. (4 marksලකුණු 4)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
URL vs body; visibility; size; uses.URL; body.

5Write PHP to save form data into MySQL and display all records.සුරැකීම සහ පෙන්වීම. (5 marksලකුණු 5)

Show model answerආදර්ශ පිළිතුර පෙන්වන්න
connect; $_POST; prepared INSERT; SELECT; loop echo table.connect; INSERT; SELECT.

🎮 Game🎮 ක්‍රීඩා

Pick a game. Each one uses words from this lesson.ක්‍රීඩාවක් තෝරන්න. හැම එකක්ම මේ පාඩමේ වචන පාවිච්චි කරනවා.

Summary & Downloadsසාරාංශය සහ බාගත කිරීම්

Key pointsප්‍රධාන කරුණු

  • Dynamic pages are built on the server.ගතික පිටු සේවාදායකයේ සාදයි.
  • PHP sits in and echoes HTML.PHP තුළ HTML echo කරයි.
  • Variables, arrays, control structures, functions.විචල්‍ය, අරා, පාලනය, ශ්‍රිත.
  • Forms send data by GET or POST.පෝරම GET හෝ POST.
  • PHP saves and retrieves MySQL data.PHP MySQL දත්ත සුරකියි/ලබා ගනී.

Downloadsබාගත කිරීම්

Full Lesson 10 PDFසම්පූර්ණ පාඩම 10 PDF: English · සිංහල

Next noteඊළඟ සටහන 10.8 →

© 2026 schoolict.net (Ruwan Mangala Suraweera). All rights reserved.සියලු හිමිකම් ඇවිරිණි.