Chapterبەش 11 · Lectureوانە 11.2
Course review and practiceپێداچوونەوە و ڕاهێنانی کۆرسەکە
The whole course in short screens: key ideas and quick checks for every chapter, the words you must know, eight practice exercises, the course book's exam questions with full answers, a midterm task with a worked solution, a 20-question output challenge, and how to use AI tools for practice responsibly.
هەموو کۆرسەکە لە شاشەی کورتدا: بیرۆکە سەرەکییەکان و پشکنینی خێرا بۆ هەموو بەشێک، ئەو وشانەی دەبێت بیانزانیت، هەشت ڕاهێنان، پرسیارەکانی تاقیکردنەوەی کتێبی کۆرسەکە بە چارەسەری تەواوەوە، ئەرکێکی نیوەی وەرز بە چارەسەرێکی کارپێکراو، تەحەدای بە 20 پرسیار و چۆنیەتی بەکارهێنانی ئامرازەکانی بۆ ڕاهێنان بە بەرپرسیارێتی.
What you will learnچی فێر دەبیت
- Recall the key ideas of every chapter and find the right lecture when you need more.
- Explain the 36 core words of the course without notes.
- Solve the eight practice exercises on your own computer.
- Answer True/False, multiple-choice and written exam questions with reasons.
- Build a form-to-table task with validation and an image upload under exam conditions.
- Predict the exact output of short PHP programs, including warnings and errors.
- Use AI chatbots for practice in a careful, honest way.
- بیرۆکە سەرەکییەکانی هەموو بەشێک بهێنیتەوە یاد و کاتێک زیاترت پێویست بوو وانەی گونجاو بدۆزیتەوە.
- 36 وشە سەرەکییەکەی کۆرسەکە بەبێ تێبینی ڕوون بکەیتەوە.
- هەشت ڕاهێنانەکە لەسەر کۆمپیوتەرەکەی خۆت چارەسەر بکەیت.
- وەڵامی پرسیارەکانی ، هەڵبژاردن و نووسینی تاقیکردنەوە بە هۆکارەوە بدەیتەوە.
- ئەرکێکی بۆ بە و بارکردنی وێنە لە بارودۆخی تاقیکردنەوەدا دروست بکەیت.
- ورد بۆ کورتی PHP پێشبینی بکەیت، و لەگەڵدا.
- بە شێوەیەکی وریا و ڕاستگۆیانە بۆ ڕاهێنان بەکاربهێنیت.
How to use this reviewچۆن ئەم پێداچوونەوەیە بەکاربهێنیت
You have reached the end of the course. This review is a series of short screens. First comes one screen for each chapter: the key ideas, links back to the full lectures, and two or three quick questions. After that you practise: the words you must know, eight exercises for your own computer, real exam questions with full answers, a midterm task with a worked solution, and a 20-question output challenge.
گەیشتیتە کۆتایی کۆرسەکە. ئەم پێداچوونەوەیە زنجیرەیەکە لە شاشەی کورت. سەرەتا بۆ هەر بەشێک شاشەیەک هەیە: بیرۆکە سەرەکییەکان، بۆ وانە تەواوەکان و دوو یان سێ پرسیاری خێرا. دوای ئەوە ڕاهێنان دەکەیت: ئەو وشانەی دەبێت بیانزانیت، هەشت ڕاهێنان بۆ کۆمپیوتەرەکەی خۆت، پرسیاری ڕاستەقینەی تاقیکردنەوە بە چارەسەری تەواوەوە، ئەرکێکی تاقیکردنەوەی نیوەی وەرز بە چارەسەرێکی کارپێکراو و تەحەدای بە 20 پرسیار.
What this course is, and who it is for
ئەم کۆرسە چییە و بۆ کێیە
- What? A step-by-step guide to web programming: how the internet works, web servers, PHP, and connecting a web page to a database.
- For whom? Students who already know a little HTML and CSS. New to them? Start with HTML Text, Images and Lists and CSS Basics. Everything else is explained from the beginning.
- The main language is PHP, and the course ends with a working database behind a web page. The original slide deck had 6 modules with 6 quick checks; CêIT splits the same material into the 10 chapters below.
- چی؟ ڕێبەرێکی هەنگاو بە هەنگاوە بۆ وێب: چۆن کار دەکات، ، و بەستنەوەی بە .
- بۆ کێ؟ ئەو خوێندکارانەی کەمێک و دەزانن. نایانزانیت؟ بە دەق، وێنە و لیست لە HTMLـدا و بنەماکانی CSS دەست پێبکە. هەموو شتێکی تر لە سەرەتاوە ڕوون کراوەتەوە.
- زمانی سەرەکی و کۆرسەکە بە کارپێکراو لە پشت کۆتایی دێت. سلایدە ڕەسەنەکان 6 مۆدیول و 6 پشکنینی خێرایان هەبوو؛ CêIT هەمان ناوەڕۆک دابەش دەکات بۆ ئەو 10 بەشەی خوارەوە.
- Do one chapter screen at a time. Answer the quick questions before you open the full lecture.
- When you get a question wrong, follow the link and read that part again — then try the question once more.
- Run every piece of code in XAMPP. If your result differs from the page, find out why.
- Say the important words out loud (see Words you should know).
- هەر جارە یەک شاشەی بەش بکە. پێش کردنەوەی وانە تەواوەکە وەڵامی پرسیارە خێراکان بدەرەوە.
- کاتێک پرسیارێکت بە هەڵە وەڵام دایەوە، بەدوای بڕۆ و ئەو بەشە دووبارە بخوێنەوە — پاشان جارێکی تر پرسیارەکە تاقی بکەرەوە.
- هەموو پارچە کۆدێک لە جێبەجێ بکە. ئەگەر ئەنجامەکەت جیاواز بوو لەوەی پەڕەکە، بزانە بۆچی.
- وشە گرنگەکان بە دەنگی بەرز بڵێ (بڕوانە ئەو وشانەی دەبێت بیانزانیت).
How to use this reviewچۆن ئەم پێداچوونەوەیە بەکاربهێنیت
The whole course on one pageهەموو کۆرسەکە لە یەک پەڕەدا
The course slides summed up the course in six modules. This table shows them, the topics they list, and where you find each topic on CêIT.
سلایدەکانی کۆرسەکە کۆرسەکەیان لە شەش مۆدیولدا کورت کردبووەوە. ئەم ئەوان، ئەو بابەتانەی تێیاندا ناوبراون و شوێنی هەر بابەتێک لە CêIT پیشان دەدات.
| Moduleمۆدیول | Topics in the slidesبابەتەکان لە سلایدەکاندا | On CêITلە CêIT |
|---|---|---|
| 1. The Internet and the Web1. و | Internet, online and offline, intranet, extranet, WWW, the skills a web developer needs، ئۆنلاین و ئۆفلاین، ، ، WWW، ئەو تواناییانەی وێب پێویستیەتی | Chapter 1: The Internet and the Web, Browsers, servers and URLs, HTTPبەشی 1: ئینتەرنێت و وێب، تۆڕگەڕ، ڕاژەکار و URL، HTTP |
| 2. Servers, XAMPP and PHP2. ، و | Browser and server, URL, Apache and IIS, XAMPP, PHP, tags, comments, variables, data types, strings و ، ، و ، ، ، ، ، ، ، | Chapters 2 and 4: XAMPP, PHP basicsبەشەکانی 2 و 4: XAMPP، بنەماکانی PHP |
| 3. Loops, Arrays and Functions3. ، و | break, continue, indexed and associative arrays, functions, functions with parametersbreak، continue، و ، ، بە | Chapters 5 and 6: Loops, Functions, Arrays, Multidimensional arraysبەشەکانی 5 و 6: خولەکان، کردارەکان، ڕیزەکەکان، ڕیزەکە فرەڕەهەندەکان |
| 4. Superglobals and Forms4. و | $_GET, $_POST, $_REQUEST, $_COOKIE, $_SESSION, $_FILES, $php_errormsg, header() redirection$_GET، $_POST، $_REQUEST، $_COOKIE، $_SESSION، $_FILES، $php_errormsg، بە header() | Chapters 7 and 9: Superglobals, Redirects, Cookies, Sessionsبەشەکانی 7 و 9: سووپەرگلۆباڵەکان، ئاڕاستەکردنەوەکان، کووکییەکان، سێشنەکان |
| 5. Databases with PHP5. لەگەڵ | SQLite and why to use it, creating a database in phpMyAdmin, connecting, inserting, a form that saves و بۆچی بەکاری بهێنین، دروستکردنی لە ، پەیوەندیکردن، INSERT، کە پاشەکەوت دەکات | Chapter 8: phpMyAdmin, Connecting, INSERT and SELECTبەشی 8: phpMyAdmin، پەیوەندیکردن، INSERT و SELECT |
| 6. SQLite Commands and Tools6. فەرمان و ئامرازەکانی | SQL92, platforms, history, DDL, DML, DQL, case sensitivity, phpLiteAdminSQL92، سەکۆکان، مێژوو، ، ، ، هەستیاری بە قەبارەی پیت، | Chapter 8: Databases and SQL, SQLite basicsبەشی 8: بنکەدراوەکان و SQL، بنەماکانی SQLite |
Chapter 1 — How the Web worksبەشی 1 — وێب چۆن کار دەکات
- The Internet is a worldwide network of networks that talk with TCP/IP. The Web (WWW) is the pages and links that use the internet. They are not the same thing.
- An intranet is private to one organisation; an extranet lets chosen outsiders in, in a controlled way.
- Tim Berners-Lee invented the Web and, in 1994, founded the W3C, which writes web standards.
- A browser (the client) asks and a web server answers. A URL has a protocol, a domain name and a path; DNS turns the domain name into an IP address.
- HTTP carries a request (method, path, headers) and a response (status code, headers, body). HTTP is stateless: each request stands alone.
- A static page is the same file for everybody; a dynamic page is built by a server-side program such as PHP for each request.
- جیهانییە لە کە بە قسە دەکەن. (WWW) ئەو پەڕە و کە بەکاردەهێنن. هەمان شت نین.
- تایبەتە بە یەک دامەزراوە؛ بە شێوەیەکی کۆنترۆڵکراو ڕێگە بە هەندێک کەسی دەرەوە دەدات بێنە ژوورەوە.
- Tim Berners-Lee داهێنا و لە ساڵی 1994دا ـی دامەزراند، کە ستانداردەکانی وێب دەنووسێت.
- () داوا دەکات و وەڵام دەداتەوە. ، و هەیە؛ دەکات بە .
- (، ، ) و (، ، لاشە) دەگوازێتەوە. HTTP : هەر بە تەنها خۆی دەوەستێت.
- هەمان بۆ هەمووان؛ بۆ هەر لەلایەن وەک PHP دروست دەکرێت.
Full lectures: The Internet and the Web · Browsers, servers and URLs · HTTP and the request cycle
وانە تەواوەکان: ئینتەرنێت و وێب · تۆڕگەڕ، ڕاژەکار و URL · HTTP و سووڕی داواکاری
Quick check
پشکنینی خێرا
Chapter 2 — Your development environmentبەشی 2 — ژینگەی پەرەپێدانەکەت
- XAMPP puts a whole web server on your computer: X (cross-platform), Apache, MariaDB/MySQL, PHP and Perl.
- Start Apache (and MySQL for databases) in the XAMPP Control Panel, then open
http://localhost. - Save your files in
C:\xampp\htdocsand open them throughhttp://localhost/.... Double-clicking a.phpfile does not run PHP. - If port 80 is busy (another program uses it), Apache will not start: close that program or move Apache to another port such as 8080 (
http://localhost:8080). - Write code in a code editor or an IDE such as VS Code or NetBeans.
- تەواو دەخاتە سەر کۆمپیوتەرەکەت: X ()، Apache، MariaDB/MySQL، PHP و Perl.
- Apache (و MySQL بۆ ) لە XAMPPـدا دەست پێبکە، پاشان
http://localhostبکەرەوە. - لە
C:\xampp\htdocsـدا پاشەکەوت بکە و لە ڕێگەیhttp://localhost/...ـەوە بیانکەرەوە. دوو کرتە لەسەر.phpPHP جێبەجێ ناکات. - ئەگەر 80 گیرابێت ( تر بەکاری دەهێنێت)، Apache دەست پێناکات: ئەو دابخە یان Apache بگوازەرەوە بۆ تر وەک 8080 (
http://localhost:8080). - کۆد لە یان وەک VS Code یان NetBeans بنووسە.
Full lectures: XAMPP: a local web server
وانە تەواوەکان: XAMPP: ڕاژەکارێکی وێبی ناوخۆیی
Quick check
پشکنینی خێرا
Chapter 3 — HTML reviewبەشی 3 — پێداچوونەوەی HTML
- Every page has the same skeleton:
<!DOCTYPE html>,<html>,<head>(with<title>and<meta charset="utf-8">) and<body>. - Tags can have attributes:
<a href="...">makes a link,<img src="..." alt="...">shows a picture. - Tables:
<table>, rows<tr>, header cells<th>, data cells<td>;colspanandrowspanjoin cells. PHP often prints its results as tables. - Forms:
<form action="..." method="get|post">with<input>(text, password, email, radio, checkbox, file, submit),<select>,<textarea>and<label>. - The
nameattribute of a control becomes the key that PHP reads:name="email"→$_POST["email"]. File uploads also needenctype="multipart/form-data".
- هەموو پەڕەیەک هەمان ئێسکەپەیکەری هەیە:
<!DOCTYPE html>،<html>،<head>(لەگەڵ<title>و<meta charset="utf-8">) و<body>. - دەتوانن هەبێت:
<a href="...">دروست دەکات،<img src="..." alt="...">وێنەیەک پیشان دەدات. - :
<table>،<tr>،<th>،<td>؛ و خانەکان یەک دەخەن. PHP زۆرجار ئەنجامەکانی وەک چاپ دەکات. - :
<form action="..." method="get|post">لەگەڵ<input>(text، password، email، radio، checkbox، file، submit)،<select>،<textarea>و<label>. -
nameدەبێتە ئەو PHP دەیخوێنێتەوە:name="email"←$_POST["email"]. پێویستی بەenctype="multipart/form-data"ـیش هەیە.
Full lectures: HTML basics · HTML forms
وانە تەواوەکان: بنەماکانی HTML · فۆرمەکانی HTML
Quick check
پشکنینی خێرا
Chapter 4 — PHP basicsبەشی 4 — بنەماکانی PHP
- PHP (“PHP: Hypertext Preprocessor”) is a server-side scripting language: the server runs it and sends only the result, usually HTML, to the browser.
- Code goes between
<?phpand?>; every statement ends with;. Comments://,#and/* ... */. echoandprintsend output;printreturns 1 and takes one argument,echocan take several.- Variables start with
$followed by a letter or_, and are case-sensitive. PHP is loosely typed: the type comes from the value. - Data types: string, integer, float, boolean, array, object, NULL (and resource).
- Constants:
define("PI", 3.14)orconst PI = 3.14;— no$, cannot change. Scope: local inside functions, global outside (global,$GLOBALS), andstaticvariables keep their value. - Strings: single quotes print exactly, double quotes insert variables; join with
.; useful functions:strlen(),strtoupper(),ucwords(),strpos(),str_replace(),trim(). - Operators: arithmetic (
+ - * / % **), assignment (+=), comparison (==value,===value and type), increment (++$x/$x++), logical (&& || !).
- («PHP: Hypertext Preprocessor») : جێبەجێی دەکات و تەنها ئەنجامەکە، زۆرجار HTML، بۆ دەنێرێت.
- کۆد دەچێتە نێوان
<?phpو?>؛ هەموو بە;کۆتایی دێت. ://،#و/* ... */. echoوprintدەنێرن؛print1 دەگەڕێنێتەوە و یەک وەردەگرێت،echoدەتوانێت چەندین وەربگرێت.- بە
$دەست پێدەکەن و دوای ئەوە پیتێک یان_دێت و . PHP : جۆرەکە لە دێت. - : ، ، ، ، ، ، (و ).
- :
define("PI", 3.14)یانconst PI = 3.14;— بێ$، ناگۆڕدرێن. : ناوخۆیی لە ناو ، گشتی لە دەرەوە (global،$GLOBALS) و دەپارێزن. - : تاکەگوتە ڕێک وەک خۆی چاپ دەکات، جووتەگوتە تێدەخات؛ بە
.پێکەوە دەلکێنرێن؛ بەسوود:strlen()،strtoupper()،ucwords()،strpos()،str_replace()،trim(). - : (
+ - * / % **)، (+=)، بەراوردکردن (==،===و جۆر)، زیادکردن (++$x/$x++)، لۆجیکی (&& || !).
Full lectures: Introduction · Syntax · echo and print · Variables · Data types · Constants and scope · Strings · Operators
وانە تەواوەکان: ناساندن · داڕستن · echo و print · گۆڕاوەکان · جۆرەکانی دراوە · نەگۆڕەکان و مەودا · زنجیرەنووسەکان · کارپێکەرەکان
Quick check
پشکنینی خێرا
<?php
$x = 5;
echo $x++ + ++$x;<?php
var_dump("5" == 5, "5" === 5);<?php
$name = "Hana";
echo 'Hi $name';Chapter 5 — Making decisions and repeating codeبەشی 5 — بڕیاردان و دووبارەکردنەوەی کۆد
if,if ... elseandif ... elseif ... elsechoose a path from a condition that is true or false.switchcompares one value with manycases. Withoutbreak, PHP falls through into the next case;defaultruns when nothing matches.whilechecks first;do ... whileruns the body at least once;forhas start, condition and step in one line;foreachwalks through an array.breakleaves the loop completely;continueskips only the current turn.
if،if ... elseوif ... elseif ... elseبەپێی کە ڕاستە یان هەڵەیە ڕێگایەک هەڵدەبژێرن.switchیەک لەگەڵ چەندینcaseبەراورد دەکات. بەبێbreak، PHP دەچێتە ناوcaseـی دواتر ()؛defaultکاتێک جێبەجێ دەبێت کە هیچیان یەک نەگرنەوە.whileسەرەتا دەپشکنێت؛do ... whileلاشەکە لانیکەم جارێک جێبەجێ دەکات؛forسەرەتا، و هەنگاو لە یەک دێڕدا کۆ دەکاتەوە؛foreachبەسەر دەڕوات.breakبە تەواوی لە دەردەچێت؛continueتەنها ئێستا دەپەڕێنێت.
Full lectures: Conditions: if and switch · Loops
وانە تەواوەکان: مەرجەکان: if و switch · خولەکان
Quick check
پشکنینی خێرا
<?php
for ($i = 1; $i <= 10; $i++) {
if ($i % 4 == 0) {
break;
}
echo $i;
}<?php
$day = 2;
switch ($day) {
case 1:
echo "A";
case 2:
echo "B";
case 3:
echo "C";
break;
default:
echo "D";
}Chapter 6 — Functions and arraysبەشی 6 — کردارەکان و ڕیزەکەکان
- A function is written once with
function name($param) { ... }and runs only when it is called.returnsends a value back and ends the function. Function names are not case-sensitive. - Parameters can have default values (
$b = 10). Normally arguments are passed by value;&$xpasses by reference, so the function can change the caller's variable. - Arrays: indexed (
$a[0]), associative ($a["name"]) and multidimensional ($a[1][0]).count()gives the size;foreach ($a as $key => $value)walks through. - Sorting:
sort/rsortsort values and renumber;asort/arsortsort by value and keep keys;ksort/krsortsort by key. echocannot show an array — useprint_r()orvar_dump().
- جارێک بە
function name($param) { ... }دەنووسرێت و تەنها کاتێک بانگ دەکرێت جێبەجێ دەبێت.returnدەگەڕێنێتەوە و کۆتایی پێدێنێت. ناوی نین. - دەتوانن هەبێت (
$b = 10). بە شێوەی ئاسایی بە شێوەی دەنێردرێن؛&$xشێوەی بەکاردەهێنێت، بۆیە دەتوانێت بانگکەرەکە بگۆڕێت. - : (
$a[0])، ($a["name"]) و ($a[1][0]).count()قەبارەکەی دەدات؛foreach ($a as $key => $value)بەسەریدا دەڕوات. - :
sort/rsortڕیز دەکەن و ژمارەکان نوێ دەکەنەوە؛asort/arsortبەپێی ڕیز دەکەن و دەپارێزن؛ksort/krsortبەپێی ڕیز دەکەن. echoناتوانێت پیشان بدات —print_r()یانvar_dump()بەکاربهێنە.
Full lectures: Functions · Arrays · Multidimensional arrays · Sorting arrays
وانە تەواوەکان: کردارەکان · ڕیزەکەکان · ڕیزەکە فرەڕەهەندەکان · ڕیزکردنی ڕیزەکەکان
Quick check
پشکنینی خێرا
<?php
function add($a, $b = 10) {
return $a + $b;
}
echo add(5);<?php
$m = [[1, 2], [3, 4]];
echo $m[1][0];Chapter 7 — Forms and user inputبەشی 7 — فۆرمەکان و نێوخستەی بەکارهێنەر
- Superglobals are built-in arrays readable everywhere:
$_GET,$_POST,$_REQUEST,$_SERVER,$_FILES,$_COOKIE,$_SESSION,$GLOBALS,$_ENV. - GET puts the data in the URL (visible, can be bookmarked, short). POST sends it in the request body — use it for passwords, files and anything that changes data.
- Validate on the server:
isset(),empty(),trim(),filter_var()andpreg_match(). Client-side checks can be skipped by an attacker. - Escape every value you print with
htmlspecialchars()(against XSS). A sticky form puts the user's values back into the inputs after an error. includegives a warning and continues if the file is missing;requirestops with a fatal error. Userequire_oncefor files such as the database connection.- Redirect with
header("Location: page.php"); exit;— before any output. - File uploads:
method="post"+enctype="multipart/form-data"; read$_FILES["f"]["name"|"tmp_name"|"size"|"error"]; check size and type; save withmove_uploaded_file().
- ئامادەن و لە هەموو شوێنێک دەخوێنرێنەوە:
$_GET،$_POST،$_REQUEST،$_SERVER،$_FILES،$_COOKIE،$_SESSION،$GLOBALS،$_ENV. - GET دەخاتە ناو (دیارە، دەکرێت هەڵبگیرێت، کورتە). POST لە لاشەی دەینێرێت — بۆ ، و هەر شتێک کە دەگۆڕێت بەکاری بهێنە.
- لەسەر بکە:
isset()،empty()،trim()،filter_var()وpreg_match(). هێرشبەر دەتوانێت پشکنینەکانی لای بپەڕێنێت. - هەموو کە چاپی دەکەیت بە
htmlspecialchars()پارێزراو بکە (دژی ). دوای دەگەڕێنێتەوە ناو خانەکان. includeئەگەر نەبێت دەدات و بەردەوام دەبێت؛requireبە دەوەستێت. بۆ وەکrequire_onceبەکاربهێنە.- بە
header("Location: page.php"); exit;بکە — پێش هەر . - :
method="post"+enctype="multipart/form-data"؛$_FILES["f"]["name"|"tmp_name"|"size"|"error"]بخوێنەوە؛ قەبارە و جۆر بپشکنە؛ بەmove_uploaded_file()پاشەکەوتی بکە.
Full lectures: Superglobals · GET and POST · Validation · Security and sticky forms · include and require · Redirects · File uploads
وانە تەواوەکان: سووپەرگلۆباڵەکان · GET و POST · پشتڕاستکردنەوە · ئاسایش و فۆرمە لکاوەکان · include و require · ئاڕاستەکردنەوەکان · بارکردنی فایل
Quick check
پشکنینی خێرا
<?php
echo htmlspecialchars("<b>Hi</b>");Chapter 8 — Databases with PHPبەشی 8 — بنکەدراوەکان لەگەڵ PHP
- A database keeps data in tables: rows (records) and columns (fields). A primary key identifies each row; it must be unique and never NULL.
AUTO_INCREMENTnumbers new rows for you. - SQL has groups of commands: DDL (
CREATE,ALTER,DROP), DML (INSERT,UPDATE,DELETE) and DQL (SELECTwithWHERE,ORDER BY,LIMIT,OFFSET). - phpMyAdmin manages MySQL/MariaDB in the browser; phpLiteAdmin does the same for SQLite.
- From PHP:
mysqli_connect()→mysqli_query()→mysqli_fetch_assoc()in a loop;mysqli_num_rows()counts the rows. - Never put user input straight into SQL: use prepared statements. Store passwords with
password_hash()and check them withpassword_verify()— nevermd5(). - A CRUD application has pages to Create, Read, Update and Delete records. SQLite keeps a whole database in one file and needs no server (serverless, zero-configuration).
- لە هەڵدەگرێت: و . هەر دەناسێنێت؛ دەبێت بێهاوتا بێت و هەرگیز NULL نەبێت.
AUTO_INCREMENTبۆ خۆی ژمارە دەداتە هەر نوێ. - چەند گرووپێک فەرمانی هەیە: (
CREATE،ALTER،DROP)، (INSERT،UPDATE،DELETE) و (SELECTلەگەڵWHERE،ORDER BY،LIMIT،OFFSET). - / لە بەڕێوە دەبات؛ هەمان کار بۆ دەکات.
- لە PHPـەوە:
mysqli_connect()←mysqli_query()←mysqli_fetch_assoc()لە ناو ؛mysqli_num_rows()دەژمێرێت. - هەرگیز ڕاستەوخۆ مەخەرە ناو SQL: بەکاربهێنە. بە
password_hash()هەڵبگرە و بەpassword_verify()بیانپشکنە — هەرگیزmd5()نا. - پەڕەی هەیە بۆ دروستکردن، خوێندنەوە، نوێکردنەوە و سڕینەوەی . هەموو لە یەک هەڵدەگرێت و پێویستی بە نییە (، بێ ڕێکخستن).
Full lectures: Databases and SQL · phpMyAdmin · Connecting · INSERT and SELECT · Database security · CRUD application · SQLite
وانە تەواوەکان: بنکەدراوەکان و SQL · phpMyAdmin · پەیوەندیکردن · INSERT و SELECT · ئاسایشی بنکەدراوە · بەرنامەی CRUD · SQLite
Quick check
پشکنینی خێرا
Chapter 9 — Cookies, sessions and loginsبەشی 9 — کووکییەکان، سێشنەکان و چوونەژوورەوە
- HTTP forgets everything between requests. Cookies and sessions are how a site remembers you.
- A cookie is a small text kept in the browser and sent back with every request.
setcookie(name, value, expire, ...)must come before any output; you read it in$_COOKIEfrom the next request; delete it with an expiry time in the past. - A session keeps data on the server. Call
session_start()at the top of every page, then use$_SESSION. The browser only holds the session ID cookie. - A login system: register with
password_hash(), log in withpassword_verify(), store the user's id in$_SESSION, protect pages by checking it, and log out withsession_unset()andsession_destroy().
- HTTP لە نێوان هەموو شتێک لەبیر دەکات. و ڕێگای ئەوەن کە تۆی لەبیر بێت.
- دەقێکی بچووکە کە لە دەمێنێتەوە و لەگەڵ هەموو دەگەڕێتەوە.
setcookie(name, value, expire, ...)دەبێت پێش هەر بێت؛ لە دواترەوە لە$_COOKIEـدا دەیخوێنیتەوە؛ بە لە ڕابردوودا دەیسڕیتەوە. - لەسەر هەڵدەگرێت. لە سەرەوەی هەموو پەڕەیەک
session_start()بانگ بکە، پاشان$_SESSIONبەکاربهێنە. تەنها هەڵدەگرێت. - سیستەمی : بە
password_hash()بکە، بەpassword_verify()بچۆ ژوورەوە، id-ـی لە$_SESSIONـدا هەڵبگرە، بە پشکنینی ئەو پەڕەکان بپارێزە و بەsession_unset()وsession_destroy()بکە.
Full lectures: Cookies · Sessions · A login system
وانە تەواوەکان: کووکییەکان · سێشنەکان · سیستەمی چوونەژوورەوە
Quick check
پشکنینی خێرا
Chapter 10 — Web APIsبەشی 10 — APIـی وێب
- An API (Application Programming Interface) is the door one application opens so other programs can use its data and features without seeing its code. Examples: Google Maps, the X (Twitter) API, weather APIs, social login.
- Benefits: cost-saving, productivity, better connection, better customer experience, marketing.
- A web API answers HTTP requests with JSON. PHP converts with
json_encode()andjson_decode($json, true), and calls APIs withfile_get_contents()or cURL.
- (Application Programming Interface) ئەو دەرگایەیە کە ئەپڵیکەیشنێک دەیکاتەوە تا تر و تواناکانی بەکاربهێنن بەبێ بینینی کۆدەکەی. نموونەکان: Google Maps، APIی X (Twitter)، کەشوهەوا، بە .
- سوودەکان: کەمکردنەوەی تێچوون، بەرهەمداری، پەیوەندیی باشتر، ئەزموونی باشتری کڕیار، بازاڕکردن.
- وێب بە وەڵامی HTTP دەداتەوە. PHP بە
json_encode()وjson_decode($json, true)دەیگۆڕێت و بەfile_get_contents()یان cURL بانگ دەکات.
Full lectures: Web APIs and JSON
وانە تەواوەکان: APIـی وێب و JSON
Quick check
پشکنینی خێرا
<?php
echo json_encode(["city" => "Duhok", "rain" => false]);Words you should knowئەو وشانەی دەبێت بیانزانیت
“Half of programming is knowing what a thing is called.” These three lists come from the course slides. Every word appeared in a lecture, so every word can be asked in an exam. The meanings below are the slides' meanings, corrected where they were outdated or too short (see the box after the tables).
«نیوەی ئەوەیە بزانیت هەر شتێک ناوی چییە.» ئەم سێ لیستە لە سلایدەکانی کۆرسەکەوە هاتوون. هەموو وشەیەک لە وانەیەکدا هاتووە، بۆیە هەموو وشەیەک دەکرێت لە تاقیکردنەوەدا بپرسرێت. ئەو واتایانەی خوارەوە واتاکانی سلایدەکانن و ئەو شوێنانەی کۆن یان زۆر کورت بوون ڕاست کراونەتەوە (بڕوانە ئەو سندوقەی دوای ).
| Wordوشە | Meaningواتا | Lectureوانە |
|---|---|---|
| A worldwide system of connected computer networks that talk with TCP/IP.سیستەمێکی جیهانییە لە بەیەکەوە بەستراو کە بە قسە دەکەن. | → | |
| A private network inside one organisation. تایبەتە لە ناو یەک دامەزراوەدا. | → | |
| An intranet that selected outsiders (partners, customers) may reach in a controlled way. کە هەندێک کەسی هەڵبژێردراوی دەرەوە (هاوبەش، کڕیار) بە شێوەیەکی کۆنترۆڵکراو دەتوانن پێی بگەن. | → | |
| (WWW) | The pages and links that sit on top of the internet.ئەو پەڕە و کە لەسەر دانراون. | → |
| The computer (and the program on it, such as Apache) that keeps and serves your pages.ئەو کۆمپیوتەرەیە (و ئەو لەسەریەتی، وەک Apache) کە پەڕەکانت هەڵدەگرێت و دەیاننێرێت. | → | |
| Internet Service Provider: the company that connects you to the internet. Hosting your site is usually done by a separate web-hosting company.Internet Service Provider: ئەو کۆمپانیایەی بە دەتبەستێتەوە. زۆرجار کۆمپانیایەکی جیا دەیکات. | → | |
| The full address of a page: protocol, domain name and path (sometimes also a port, a query string and a fragment).ناونیشانی تەواوی پەڕەیەک: ، و (هەندێک جار ، و فراگمێنتیش). | → | |
| The service that turns a domain name into an IP address.ئەو خزمەتگوزارییەیە کە دەکات بە . | → | |
| One of the most popular web servers in the world; free and open source.یەکێکە لە ناودارترین جیهان؛ بەخۆڕایی و . | → | |
| Microsoft's web server, running on Windows. Microsoftـە، لەسەر Windows کار دەکات. | → | |
| X (cross-platform), Apache, MariaDB/MySQL, PHP and Perl in one installer.X ()، Apache، MariaDB/MySQL، PHP و Perl لە یەک دامەزرێنەردا. | → | |
| “PHP: Hypertext Preprocessor”, a server-side scripting language.«PHP: Hypertext Preprocessor»، . | → |
Words you should knowئەو وشانەی دەبێت بیانزانیت
Part 2 — the PHP languageبەشی 2 — زمانی PHP
| Wordوشە | Meaningواتا | Lectureوانە |
|---|---|---|
A named box that holds a value. In PHP its name starts with $.سندوقێکی ناونراوە کە هەڵدەگرێت. لە PHPـدا ناوەکەی بە $ دەست پێدەکات. | → | |
| PHP works out the data type for you from the value.PHP خۆی لە دەدۆزێتەوە. | → | |
| A whole number, with no decimal point.ژمارەیەکی بێ کەرت، بێ خاڵی دەیی. | → | |
| A number with a decimal point.ژمارەیەک بە خاڵی دەییەوە. | → | |
Only two values: true or false.تەنها دوو : true یان false. | → | |
A special type with one value: null (no value).جۆرێکی تایبەتە بە یەک : null (بێ ). | → | |
| A sequence of characters inside quotes.زنجیرەیەک نووسەیە لە ناو گوتەدا. | → | |
| One variable holding many values.یەک کە چەندین هەڵدەگرێت. | → | |
| An array whose keys are names (strings) that you choose. (PHP even lets one array mix string and number keys.) کە ناون () و خۆت هەڵیان دەبژێریت. (PHP تەنانەت ڕێگە دەدات یەک و ژمارە تێکەڵ بکات.) | → | |
| A named piece of code that you can call again and again.پارچە کۆدێکی ناونراوە کە دەتوانیت جار لە دوای جار بانگی بکەیت. | → | |
| / | The parameter is the variable in the function's definition ($a); the argument is the value you pass when you call it (5). ئەو کە لە هەیە ($a)؛ ئەو نرخەیە کە لە کاتی بانگکردندا دەینێریت (5). | → |
A built-in variable that PHP fills in and that you can read anywhere, such as $_POST. ئامادەیە کە PHP پڕی دەکاتەوە و لە هەموو شوێنێک دەتوانیت بیخوێنیتەوە، وەک $_POST. | → |
Words you should knowئەو وشانەی دەبێت بیانزانیت
Part 3 — databases and toolsبەشی 3 — بنکەدراوەکان و ئامرازەکان
| Wordوشە | Meaningواتا | Lectureوانە |
|---|---|---|
| A database engine that keeps a whole database in one file.بزوێنەرێکی کە هەموو لە یەک هەڵدەگرێت. | → | |
| No separate server process is needed.پێویستی بە پرۆسەیەکی جیای نییە. | → | |
| Zero-configuration | Nothing to install or set up before you use it.پێش بەکارهێنان هیچ شتێک پێویستی بە دامەزراندن یان ڕێکخستن نییە. | → |
| Self-contained | Needs very little from outside libraries or the operating system.پێویستییەکی زۆر کەمی بە دەرەکی یان سیستەمی کارپێکردن هەیە. | → |
| SQL92 (SQL2) | A version of the SQL standard; SQLite follows most of it.وەشانێکی ستانداردی ؛ زۆربەی پەیڕەو دەکات. | → |
Data Definition Language: CREATE, ALTER, DROP.زمانی پێناسەکردنی (Data Definition Language): CREATE، ALTER، DROP. | → | |
Data Manipulation Language: INSERT, UPDATE, DELETE.زمانی دەستکاریکردنی (Data Manipulation Language): INSERT، UPDATE، DELETE. | → | |
Data Query Language: SELECT.زمانی پرسکردنی (Data Query Language): SELECT. | → | |
| The web tool for managing MySQL and MariaDB.ئامرازی وێبە بۆ بەڕێوەبردنی و . | → | |
| The web tool for managing SQLite.ئامرازی وێبە بۆ بەڕێوەبردنی . | → | |
| The column whose value identifies every row: it must be unique and can never be NULL.ئەو کە هەموو دەناسێنێت: دەبێت بێهاوتا بێت و هەرگیز NULL نەبێت. | → | |
| The open link between your PHP code and the database.ئەو بەستەرە کراوەیەیە لە نێوان کۆدی PHPـەکەت و . | → |
Words you should knowئەو وشانەی دەبێت بیانزانیت
What was corrected, and a self-testچی ڕاست کرایەوە و تاقیکردنەوەی خۆت
Cover the Meaning column with a sheet of paper. For each of the 36 words, explain it out loud in one or two sentences, then uncover and check. If you can explain a word without your notes, you know it. Mark the words you missed and try them again tomorrow.
ستوونی واتا بە پەڕەیەک دابپۆشە. بۆ هەر یەکێک لە 36 وشەکە، بە دەنگی بەرز لە یەک یان دوو ڕستەدا ڕوونی بکەرەوە، پاشان لای ببە و بیپشکنە. ئەگەر توانیت وشەیەک بەبێ تێبینییەکانت ڕوون بکەیتەوە، ئەوا دەیزانیت. ئەو وشانەی نەتزانین نیشانە بکە و سبەی دووبارە تاقییان بکەرەوە.
Show answerوەڵامەکە پیشان بدە
What is the difference between a parameter and an argument?جیاوازیی نێوان پارامیتەر و ئارگیومێنت چییە؟
In function add($a, $b), $a and $b are parameters. In add(2, 3), 2 and 3 are the arguments.
لە function add($a, $b)ـدا $a و $b . لە add(2, 3)ـدا 2 و 3 .
What do serverless and zero-configuration mean for SQLite?بێڕاژەکار و بێڕێکخستن (zero-configuration) بۆ SQLite واتای چین؟
Serverless: no separate database server runs — your PHP reads the file directly. Zero-configuration: nothing to install or set up first.
: هیچ جیای کار ناکات — PHPـەکەت ڕاستەوخۆ دەخوێنێتەوە. بێڕێکخستن: پێشتر هیچ شتێک دامەزراندن یان ڕێکخستنی ناوێت.
What does “loosely typed” mean?«loosely typed» واتای چییە؟
You do not declare a type: $x = 5; makes an integer and $x = "5"; a string. PHP decides from the value.
جۆر ڕاناگەیەنیت: $x = 5; دروست دەکات و $x = "5"; . PHP لە بڕیار دەدات.
Is phpMyAdmin a database?ئایا phpMyAdmin بنکەدراوەیە؟
No. It is a PHP web application — a window onto MySQL/MariaDB. The database server itself is MySQL/MariaDB.
نەخێر. PHPـیە — پەنجەرەیەک بۆ سەر /. خودی /.
Which three command groups of SQL did the course teach, and one example of each?کۆرسەکە کام سێ گرووپی فەرمانی SQLـی فێر کرد و نموونەیەک لە هەر یەکەیان؟
DDL: CREATE; DML: INSERT; DQL: SELECT.
: CREATE؛ : INSERT؛ : SELECT.
Exams often ask what the letters stand for. Write the full words for: SQL, HTML, CSS, ISP, JS, URL, DNS, PHP.
تاقیکردنەوەکان زۆرجار دەپرسن پیتەکان کورتکراوەی چین. وشە تەواوەکان بنووسە بۆ: SQL، HTML، CSS، ISP، JS، URL، DNS، PHP.
Show answerوەڵامەکە پیشان بدە
- SQL: Structured Query Language
- HTML: HyperText Markup Language
- CSS: Cascading Style Sheets
- ISP: Internet Service Provider
- JS: JavaScript
- URL: Uniform Resource Locator
- DNS: Domain Name System
- PHP: PHP: Hypertext Preprocessor (a recursive name: the first P is PHP itself; it began as Personal Home Page)
- SQL: Structured Query Language (زمانی پرسیاری )
- HTML: HyperText Markup Language ( بۆ لاپەڕەکان)
- CSS: Cascading Style Sheets (شێوەی لاپەڕەکان)
- ISP: Internet Service Provider (ئەو کۆمپانیایەی تۆ بە دەبەستێتەوە)
- JS: JavaScript (زمانی لە )
- URL: Uniform Resource Locator (ناونیشانی تەواوی لاپەڕەیەک)
- DNS: Domain Name System ( دەکاتە )
- PHP: PHP: Hypertext Preprocessor (ناوێکی خولاوە: P یەکەم خۆی PHPـە؛ سەرەتا Personal Home Page بوو)
Practise on your own computer: eight exercisesلەسەر کۆمپیوتەرەکەی خۆت ڕاهێنان بکە: هەشت ڕاهێنان
These eight exercises follow the order in which you learned the topics. Try each one before you open the answer.
ئەم هەشت ڕاهێنانە بە هەمان ڕیزبەندیی فێربوونی بابەتەکانن. پێش کردنەوەی چارەسەرەکە هەر یەکەیان تاقی بکەرەوە.
Install XAMPP, start Apache and MySQL, and open http://localhost.
دابمەزرێنە، Apache و MySQL دەست پێبکە و http://localhost بکەرەوە.
Show answerوەڵامەکە پیشان بدە
Download XAMPP for your system from the official site, apachefriends.org, and run the installer. Keep the default folder
C:\xampp.بۆ سیستەمەکەت لە ماڵپەڕی فەرمی apachefriends.org دابەزێنە و دامەزرێنەرەکە کارپێبکە. بنەڕەتی
C:\xamppبهێڵەرەوە.Open the XAMPP Control Panel and press Start next to Apache and next to MySQL. Their names turn green.
XAMPP بکەرەوە و لە تەنیشت Apache و MySQL دوگمەی Start دابگرە. ناوەکانیان سەوز دەبن.
Open your browser at
http://localhost. You see the XAMPP dashboard page. If Apache does not start, another program is using port 80: close it, or change Apache's port.لە
http://localhostبکەرەوە. پەڕەی داشبۆردی XAMPP دەبینیت. ئەگەر Apache دەست پێنەکرد، تر 80 بەکاردەهێنێت: دایبخە، یان Apache بگۆڕە.
More detail: XAMPP: a local web server.
وردەکاریی زیاتر: XAMPP: ڕاژەکارێکی وێبی ناوخۆیی.
Save a file called index.php in htdocs that prints Hello world!, and open it in the browser.
بە ناوی index.php لە htdocsـدا پاشەکەوت بکە کە Hello world! چاپ بکات و لە بیکەرەوە.
Show answerوەڵامەکە پیشان بدە
<!DOCTYPE html>
<html>
<body>
<?php
echo "Hello world!";
?>
</body>
</html>Hello world!
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<!DOCTYPE html>
<html>
<body>
Hello world!</body>
</html>Open it as http://localhost/index.php (or just http://localhost/, because Apache shows index.php by default). The ?> also swallows the line break after it, so </body> follows directly.
وەک http://localhost/index.php بیکەرەوە (یان تەنها http://localhost/، چونکە Apache بە شێوەی بنەڕەتی index.php پیشان دەدات). ?> هێڵە نوێیەکەی دوای خۆیشی قووت دەدات، بۆیە </body> ڕاستەوخۆ دوای دێت.
Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 5
echosends the text into the HTML page.echoدەقەکە دەنێرێتە ناو پەڕە HTMLـەکە.
Practise on your own computer: eight exercisesلەسەر کۆمپیوتەرەکەی خۆت ڕاهێنان بکە: هەشت ڕاهێنان
Exercises 3–6: variables, loops, arrays and functionsڕاهێنانەکانی 3–6: گۆڕاوەکان، خولەکان، ڕیزەکەکان و کردارەکان
Make a string, an integer and a float, and print all three.
، و دروست بکە و هەر سێکیان چاپ بکە.
Show answerوەڵامەکە پیشان بدە
<?php
$name = "Hana"; // string
$age = 19; // integer
$price = 2.75; // float
echo $name . "<br>";
echo $age . "<br>";
echo $price . "<br>";
var_dump($name, $age, $price);Hana 19 2.75 string(4) "Hana" int(19) float(2.75)
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Hana<br>19<br>2.75<br>string(4) "Hana"
int(19)
float(2.75)Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2-4
PHP decides the type from the value: quotes → string, whole number → int, decimal point → float.
PHP جۆرەکە لە دیاری دەکات: گوتە ← ، ← int، خاڵی دەیی ← float.
- Lineدێڕی 10
var_dump()shows the type and the value — good for checking.var_dump()جۆر و پیشان دەدات — بۆ پشکنین باشە.
(a) Print the numbers 0 to 9. (b) Do it again, but skip 3 with continue. (c) Do it again, but stop at 3 with break.
(أ) ژمارەکانی 0 تا 9 چاپ بکە. (ب) دووبارەی بکەرەوە، بەڵام بە continue 3 بپەڕێنە. (ج) دووبارەی بکەرەوە، بەڵام بە break لە 3 بوەستە.
Show answerوەڵامەکە پیشان بدە
<?php
for ($i = 0; $i <= 9; $i++) {
echo $i . " ";
}0 1 2 3 4 5 6 7 8 9
<?php
for ($i = 0; $i <= 9; $i++) {
if ($i == 3) {
continue; // skip 3, go on with 4
}
echo $i . " ";
}0 1 2 4 5 6 7 8 9
<?php
for ($i = 0; $i <= 9; $i++) {
if ($i == 3) {
break; // leave the loop completely
}
echo $i . " ";
}0 1 2
continue jumps to the next turn of the loop; break leaves the loop completely, so 3 and everything after it is never printed.
continue باز دەدات بۆ دواتری ؛ break بە تەواوی لە دەردەچێت، بۆیە 3 و هەرچی دوای ئەوە هەرگیز چاپ ناکرێن.
Store five names in an array and print them one under the other.
پێنج ناو لە هەڵبگرە و یەک لە ژێر یەکی تر چاپیان بکە.
Show answerوەڵامەکە پیشان بدە
<?php
$names = ["Aram", "Shilan", "Karwan", "Dilan", "Rezan"];
foreach ($names as $name) {
echo $name . "<br>";
}Aram Shilan Karwan Dilan Rezan
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
Aram<br>Shilan<br>Karwan<br>Dilan<br>Rezan<br>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 4
foreachgives you each value in turn;<br>puts the next name on a new line in the browser.foreachهەر بە نۆرە دەدات؛<br>ناوی دواتر لە دەخاتە دێڕێکی نوێ.
Write a function add($a, $b) that returns the sum, and call it three times.
بە ناوی add($a, $b) بنووسە کە کۆکەی دوو ژمارەکە بگەڕێنێتەوە و سێ جار بانگی بکە.
Show answerوەڵامەکە پیشان بدە
<?php
function add($a, $b) {
return $a + $b;
}
echo add(2, 3) . "<br>";
echo add(10, 20) . "<br>";
echo add(1.5, 2.5) . "<br>";5 30 4
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
5<br>30<br>4<br>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 2-4
Written once…
جارێک نووسراوە…
- Lineدێڕی 6-8
…called three times with different arguments.
…سێ جار بە جیاواز بانگ کراوە.
Practise on your own computer: eight exercisesلەسەر کۆمپیوتەرەکەی خۆت ڕاهێنان بکە: هەشت ڕاهێنان
Exercises 7–8: a form and a databaseڕاهێنانەکانی 7–8: فۆرمێک و بنکەدراوەیەک
Make a form with two text boxes and a submit button, and read the two values with $_POST.
بە دوو و دروست بکە و هەردوو بە $_POST بخوێنەوە.
Show answerوەڵامەکە پیشان بدە
<?php
$message = "";
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$name = trim($_POST["name"] ?? "");
$city = trim($_POST["city"] ?? "");
if ($name === "" || $city === "") {
$message = "Please fill in both boxes.";
} else {
$message = "Hello " . htmlspecialchars($name)
. " from " . htmlspecialchars($city) . "!";
}
}
?>
<!DOCTYPE html>
<html>
<body>
<form method="post" action="form.php">
Name: <input type="text" name="name"><br>
City: <input type="text" name="city"><br>
<input type="submit" value="Send">
</form>
<p><?php echo $message; ?></p>
</body>
</html>Name: [ ] City: [ ] [Send] Hello Shilan from Slemani!
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<!DOCTYPE html>
<html>
<body>
<form method="post" action="form.php">
Name: <input type="text" name="name"><br>
City: <input type="text" name="city"><br>
<input type="submit" value="Send">
</form>
<p>Hello Shilan from Slemani!</p>
</body>
</html>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 4
Only after a submit is the request method POST.
تەنها دوای ناردن ڕێگای POST دەبێت.
- Lineدێڕی 5-6
?? ""gives an empty string if the box is missing;trim()removes spaces.?? ""ئەگەر خانەکە نەبێت بەتاڵ دەدات؛trim()لادەبات.- Lineدێڕی 11-12
htmlspecialchars()makes the user's text safe to print.htmlspecialchars()دەقی بۆ چاپکردن سەلامەت دەکات.- Lineدێڕی 20-21
The
nameattributes become the keys of$_POST.nameدەبنە$_POST.
Please fill in both boxes.
Read more: GET and POST and Form validation.
زیاتر بخوێنەوە: GET و POST و پشتڕاستکردنەوەی فۆرم.
Create a table in phpMyAdmin and save the form from exercise 7 into it.
لە دروست بکە و ڕاهێنانی 7ی تێدا پاشەکەوت بکە.
Show answerوەڵامەکە پیشان بدە
In phpMyAdmin (
http://localhost/phpmyadmin) create a database calledpractice.لە (
http://localhost/phpmyadmin) بە ناویpracticeدروست بکە.Open its SQL tab and run this statement (or build the same three columns with the Create table form):
تابی SQLـی بکەرەوە و ئەم فەرمانە جێبەجێ بکە (یان هەمان سێ بە Create table دروست بکە):
CREATE TABLE visitors (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
city VARCHAR(50) NOT NULL
);<?php
// dbcon.php - opens the connection to the "practice" database
$con = mysqli_connect("localhost", "root", "", "practice");
mysqli_set_charset($con, "utf8mb4");<?php
// save.php - the form from exercise 7, now saved into the database
require_once "dbcon.php";
$message = "";
if ($_SERVER["REQUEST_METHOD"] === "POST") {
$name = trim($_POST["name"] ?? "");
$city = trim($_POST["city"] ?? "");
if ($name === "" || $city === "") {
$message = "Please fill in both boxes.";
} else {
try {
// A prepared statement keeps the user's text away from the SQL
$stmt = mysqli_prepare($con, "INSERT INTO visitors (name, city) VALUES (?, ?)");
mysqli_stmt_bind_param($stmt, "ss", $name, $city);
mysqli_stmt_execute($stmt);
$message = "Saved! New id: " . mysqli_insert_id($con);
} catch (mysqli_sql_exception $e) {
$message = "Sorry, the data could not be saved.";
}
}
}
?>
<!DOCTYPE html>
<html>
<body>
<form method="post" action="save.php">
Name: <input type="text" name="name"><br>
City: <input type="text" name="city"><br>
<input type="submit" value="Save">
</form>
<p><?php echo htmlspecialchars($message); ?></p>
</body>
</html>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 3
require_onceloads the connection file (once) and stops the page if it is missing. It gives us$con.require_onceپەیوەندییەکە (یەک جار) بار دەکات و ئەگەر نەبێت پەڕەکە ڕادەگرێت.$conـمان دەداتێ.- Lineدێڕی 16-18
A prepared statement: the SQL has
?places, and the values are sent separately, so nobody can change your SQL (no SQL injection).: SQLـەکە شوێنی
?ـی تێدایە و بە جیا دەنێردرێن، بۆیە کەس ناتوانێت SQLـەکەت بگۆڕێت (هیچ نییە).- Lineدێڕی 20-22
Since PHP 8.1, mysqli throws an exception when something fails, so we catch it.
لە PHP 8.1ـەوە، mysqli کاتێک شتێک شکست دەهێنێت فڕێ دەدات، بۆیە دەیگرین.
The same idea with SQLite (PDO), which you can run without MySQL:
هەمان بیرۆکە بە (PDO)، کە دەتوانیت بەبێ MySQL جێبەجێی بکەیت:
<?php
// The same idea with SQLite (PDO), so you can try it without MySQL
$db = new PDO("sqlite::memory:");
$db->exec("CREATE TABLE visitors (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
city TEXT NOT NULL
)");
$stmt = $db->prepare("INSERT INTO visitors (name, city) VALUES (?, ?)");
$stmt->execute(["Shilan", "Slemani"]);
$stmt->execute(["Rezan", "Hewlêr"]);
foreach ($db->query("SELECT id, name, city FROM visitors") as $row) {
echo $row["id"] . ": " . $row["name"] . " - " . $row["city"] . "\n";
}1: Shilan - Slemani 2: Rezan - Hewlêr
Open practice → visitors → Browse in phpMyAdmin after sending the form, and you will see the new rows. More: phpMyAdmin, INSERT and SELECT, Database security.
دوای ناردنی ، لە practice → visitors → Browse بکەرەوە و دەبینیت. زیاتر: phpMyAdmin، INSERT و SELECT، ئاسایشی بنکەدراوە.
Exam questions from the course bookپرسیارەکانی تاقیکردنەوە لە کتێبی کۆرسەکەوە
The course book ends with sample exam questions: one written question, five True/False questions and three multiple-choice questions (the True/False group and the multiple-choice group are worth 25 marks each). The book gives no answers, so here every question has a full, tested answer.
کتێبی کۆرسەکە بە نموونەی پرسیاری تاقیکردنەوە کۆتایی دێت: یەک پرسیاری نووسین، پێنج پرسیاری و سێ پرسیاری هەڵبژاردن (گرووپی و گرووپی هەڵبژاردن هەر یەکەیان 25 نمرەیە). کتێبەکە چارەسەر نادات، بۆیە لێرەدا هەموو پرسیارێک چارەسەرێکی تەواو و تاقیکراوەی هەیە.
Written question
پرسیاری نووسین
What are the types of arrays? Explain them and give an example of each.
جۆرەکانی چین؟ ڕوونیان بکەرەوە و نموونەیەک بۆ هەر یەکەیان بهێنەرەوە.
Show answerوەڵامەکە پیشان بدە
- Indexed array — PHP numbers the values for you, starting at 0.
- Associative array — you give every value a name (a key).
- Multidimensional array — an array that contains other arrays, like a table with rows and columns.
- — PHP خۆی ژمارە دەداتە ، لە 0ـەوە.
- — خۆت ناوێک () دەدەیتە هەر .
- — کە تری تێدایە، وەک بە و ستوونەکانەوە.
<?php
// 1. Indexed array: numbers are the keys (0, 1, 2 ...)
$cities = ["Slemani", "Hewlêr", "Duhok"];
echo $cities[0] . "\n";
// 2. Associative array: you choose the keys
$student = ["name" => "Aram", "age" => 21];
echo $student["name"] . " is " . $student["age"] . "\n";
// 3. Multidimensional array: arrays inside an array
$marks = [
["Aram", 90, 85],
["Hana", 78, 94],
];
echo $marks[1][0] . " got " . $marks[1][2] . "\n";Slemani Aram is 21 Hana got 94
More: Arrays, Multidimensional arrays.
زیاتر: ڕیزەکەکان، ڕیزەکە فرەڕەهەندەکان.
Exam questions from the course bookپرسیارەکانی تاقیکردنەوە لە کتێبی کۆرسەکەوە
How web exams ask: nine question stylesتاقیکردنەوەکانی وێب چۆن دەپرسن: نۆ شێوازی پرسیار
Web exams often use the same nine kinds of question. Each kind wants a different answer, so first see which kind you have. The first five:
تاقیکردنەوەکانی وێب زۆرجار هەمان نۆ جۆری پرسیار بەکار دەهێنن. هەر جۆرێک وەڵامێکی جیاوازی دەوێت، بۆیە سەرەتا بزانە کام جۆرەت لەبەردەمە. پێنجی یەکەم:
| Styleشێواز | What the examiner wantsمامۆستا چی دەوێت | Try oneیەکێک تاقی بکەرەوە |
|---|---|---|
| 1. Define or describe١. پێناسە یان وەسف | A short, exact definition in your own words, often with one example.پێناسەیەکی کورت و ورد بە وشەی خۆت، زۆرجار لەگەڵ نموونەیەک. | Define a web server (answer). پێناسە بکە (وەڵام). |
| 2. Wh-question: what, why, how, which, when٢. پرسیاری «چی، بۆچی، چۆن، کام، کەی» | An open question: it has many possible answers. Explain, give reasons and an example: a few sentences or a list, never one word.پرسیارێکی کراوە: چەندین وەڵامی هەیە. ڕوونی بکەرەوە، هۆکار و نموونە بهێنەوە: چەند ڕستەیەک یان لیستێک، هەرگیز یەک وشە نا. | Why is HTTP called stateless? (answer)بۆچی بە دەوترێت ؟ (وەڵام) |
| 3. Compare٣. بەراورد | The differences, best as a table with the same rows for both things.جیاوازییەکان، باشترە لە خشتەیەکدا بە هەمان ڕیز بۆ هەردوو شتەکە. | Compare GET and POST (answer).GET و POST بەراورد بکە (وەڵام). |
| 4. Abbreviations٤. | The full words behind every letter, spelled correctly.وشە تەواوەکانی پشت هەر پیتێک، بە ڕێنووسی دروست. | What does URL stand for? (drill)URL کورتکراوەی چییە؟ (ڕاهێنان) |
| 5. Fill the blank٥. بۆشایی پڕ بکەرەوە | One exact word or a short phrase that makes the sentence true.یەک وشەی ورد یان دەستەواژەیەکی کورت کە ڕستەکە ڕاست دەکات. | "… can contain the <script> tags." (answer)«… دەتوانێت تاگەکانی <script>ـی تێدا بێت.» (وەڵام) |
Exam questions from the course bookپرسیارەکانی تاقیکردنەوە لە کتێبی کۆرسەکەوە
Nine question styles (continued)نۆ شێوازی پرسیار (بەردەوام)
| Styleشێواز | What the examiner wantsمامۆستا چی دەوێت | Try oneیەکێک تاقی بکەرەوە |
|---|---|---|
| 6. Choose or select the word٦. وشە هەڵبژێرە | Pick from the options, or from a box of words where each word is used once.لە نێوان بژاردەکاندا هەڵبژێرە، یان لە سندووقێکی وشە کە هەر وشەیەک یەک جار بەکار دێت. | "… lets you use the Internet away from home, with no Wi-Fi." (answer)«… ڕێگەت پێدەدات لە دەرەوەی ماڵ و بێ بەکار بهێنیت.» (وەڵام) |
| 7. True or false, and correct the false ones٧. لەگەڵ ڕاستکردنەوەی هەڵەکان | Decide, then rewrite every false sentence so it becomes true.بڕیار بدە، پاشان هەر ڕستەیەکی هەڵە دووبارە بنووسەوە تا ڕاست بێت. | "The World Wide Web is the same as the Internet." (answer)« هەمان .» (وەڵام) |
| 8. Match٨. لێکدان | Join each term to its meaning, one to one. Cross out what you have used.هەر زاراوەیەک بە واتاکەیەوە ببەستەوە، یەک بە یەک. ئەوەی بەکارت هێنا بیکوژێنەوە. | Match web server, IP address and POST with their meanings (answers).، و POST لەگەڵ واتاکانیان لێک بدە (وەڵامەکان). |
| 9. Write code or design a page٩. کۆد بنووسە یان لاپەڕە دیزاین بکە | Working code: the full page skeleton, correct tags, straight quotes. For a design, plan the pages first.کۆدی کارا: هەموو ئێسکەپەیکەری لاپەڕەکە، تاگی دروست و ڕاست. بۆ دیزاین، سەرەتا پلانی لاپەڕەکان دابنێ. | Write a registration form (lab); design a site with one page per department (capstones). تۆمارکردن بنووسە (تاقیگە)؛ دیزاین بکە کە هەر بەشێک لاپەڕەیەکی خۆی هەبێت (پڕۆژەکان). |
Exam questions from the course bookپرسیارەکانی تاقیکردنەوە لە کتێبی کۆرسەکەوە
True or Falseڕاست یان هەڵە
<?php
$text = "welcome to web programming";
echo ucwords($text) . "\n"; // first letter of EVERY word -> capital
echo strtolower("HELLO") . "\n"; // this is the function that makes lowercase
echo ucfirst($text) . "\n"; // only the first letter of the stringWelcome To Web Programming hello Welcome to web programming
<?php
$first = "Web";
$second = "Programming";
echo $first . " " . $second . "\n";
$title = $first;
$title .= " Programming"; // .= adds to the end of the string
echo $title;Web Programming Web Programming
<?php
function greet() {
echo "Hello from the function!\n";
}
echo "Page loaded.\n"; // the function has not run yet
greet(); // now it runs
greet(); // and againPage loaded. Hello from the function! Hello from the function!
<?php
$i = 10;
while ($i < 5) { // checked FIRST: 10 < 5 is false
echo "while: $i\n"; // never runs
}
do {
echo "do...while: $i\n"; // runs once BEFORE the check
} while ($i < 5);do...while: 10
<?php
$db = new PDO("sqlite::memory:");
$db->exec("CREATE TABLE students (id INTEGER PRIMARY KEY, name TEXT)");
foreach (["Aram", "Shilan", "Karwan", "Dilan", "Rezan", "Hana"] as $n) {
$db->prepare("INSERT INTO students (name) VALUES (?)")->execute([$n]);
}
echo "LIMIT 2:\n";
foreach ($db->query("SELECT id, name FROM students ORDER BY id LIMIT 2") as $r) {
echo " " . $r["id"] . " " . $r["name"] . "\n";
}
echo "LIMIT 2 OFFSET 2:\n";
foreach ($db->query("SELECT id, name FROM students ORDER BY id LIMIT 2 OFFSET 2") as $r) {
echo " " . $r["id"] . " " . $r["name"] . "\n";
}LIMIT 2: 1 Aram 2 Shilan LIMIT 2 OFFSET 2: 3 Karwan 4 Dilan
Exam questions from the course bookپرسیارەکانی تاقیکردنەوە لە کتێبی کۆرسەکەوە
Choose the correct answerهەڵبژاردەی دروست دیاری بکە
<?php
$var = "valid";
$_count = 1;
$name2 = "also valid";
echo $var . " " . $_count . " " . $name2;valid 1 also valid
$1var = ...;, £Var = 5; and Var = 5; (each tried in its own file)ئەوەی PHP 8.5 بە $1var = ...;، £Var = 5; و Var = 5; دەڵێت (هەر یەکەیان لە فایلێکی جیادا تاقی کراوەتەوە)Parse error: syntax error, unexpected integer "1", expecting variable or "{" or "$" in C:\xampp\htdocs\names.php on line 2
Parse error: syntax error, unexpected token "=" in C:\xampp\htdocs\names.php on line 2
Parse error: syntax error, unexpected token "var", expecting end of file in C:\xampp\htdocs\names.php on line 2<?php
$input = " Shilan ";
var_dump($input);
var_dump(trim($input)); // both ends
var_dump(ltrim($input)); // left side only
var_dump(rtrim($input)); // right side onlystring(12) " Shilan " string(6) "Shilan" string(9) "Shilan " string(9) " Shilan"
A midterm task with a full solutionئەرکێکی تاقیکردنەوەی نیوەی وەرز بە چارەسەری تەواوەوە
This task comes from a practice midterm of the course (Midterm – Practice, Sample A: one question, one hour, 10 marks). It tests forms, form handling, validation and file uploads — not cookies or sessions. The text is rewritten clearly below; the student details on the original paper are left out.
ئەم ئەرکە لە تاقیکردنەوەیەکی ڕاهێنانی نیوەی وەرزی کۆرسەکەوە هاتووە (Midterm – Practice, Sample A: یەک پرسیار، یەک کاتژمێر، 10 نمرە). فۆرمەکان، مامەڵەکردن لەگەڵ فۆرم، پشتڕاستکردنەوە و بارکردنی فایل تاقی دەکاتەوە — نەک یان . دەقەکە لە خوارەوە بە ڕوونی نووسراوەتەوە؛ زانیارییەکانی خوێندکار لەسەر پەڕە ڕەسەنەکە لابراون.
The paper showed two pictures of the expected result. Here they are rebuilt as HTML:
پەڕەکە دوو وێنەی ئەنجامی چاوەڕوانکراوی پیشان دابوو. لێرەدا وەک HTML دووبارە دروست کراونەتەوە:
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<h2>Registration Form</h2>
<form action="Profile.php" method="post" enctype="multipart/form-data">
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter username"><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter password"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter email"><br><br>
<label for="avatar">Image:</label>
<input type="file" id="avatar" name="avatar" accept="image/*"><br><br>
<input type="submit" name="register" value="Register">
</form>Labels from top to bottom: Username, Password, Email, Image (a file chooser), then the Register button.
لەیبڵەکان لە سەرەوە بۆ خوارەوە: Username، Password، Email، Image (هەڵبژاردنی )، پاشان دوگمەی Register.
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<table border="1">
<tr><th>Username</th><th>Password</th><th>Email</th><th>Avatar</th></tr>
<tr><td>IT_Stage_2</td><td>password123</td><td>it_stage2@example.com</td><td>[avatar picture]</td></tr>
</table>Four columns — Username, Password, Email, Avatar — with the sample row from the paper (the avatar was a grey person picture; the email address is changed to an example.com address).
چوار ستوون — Username، Password، Email، Avatar — لەگەڵ نموونە لە پەڕەکەوە (Avatar وێنەیەکی خۆڵەمێشیی کەسێک بوو؛ گۆڕدراوە بۆ ناونیشانێکی example.com).
A midterm task with a full solutionئەرکێکی تاقیکردنەوەی نیوەی وەرز بە چارەسەری تەواوەوە
Plan your answerپلانی چارەسەرەکەت دابنێ
A midterm task with a full solutionئەرکێکی تاقیکردنەوەی نیوەی وەرز بە چارەسەری تەواوەوە
Worked solution, part 1: Register.phpچارەسەری کارپێکراو، بەشی 1: Register.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Registration Form</title>
</head>
<body>
<h2>Registration Form</h2>
<form action="Profile.php" method="post" enctype="multipart/form-data">
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter username"><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter password"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter email"><br><br>
<label for="avatar">Image:</label>
<input type="file" id="avatar" name="avatar" accept="image/*"><br><br>
<input type="submit" name="register" value="Register">
</form>
</body>
</html>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<h2>Registration Form</h2>
<form action="Profile.php" method="post" enctype="multipart/form-data">
<label for="username">Username:</label>
<input type="text" id="username" name="username" placeholder="Enter username"><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" placeholder="Enter password"><br><br>
<label for="email">Email:</label>
<input type="email" id="email" name="email" placeholder="Enter email"><br><br>
<label for="avatar">Image:</label>
<input type="file" id="avatar" name="avatar" accept="image/*"><br><br>
<input type="submit" name="register" value="Register">
</form>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 10
actionsends the form toProfile.php;posthides the password from the URL;multipart/form-datais required for the file.actionدەنێرێت بۆProfile.php؛postلە دەشارێتەوە؛multipart/form-dataبۆ پێویستە.- Lineدێڕی 11-18
Each
namebecomes a key in$_POSTon the next page.type="password"shows dots;type="email"lets the browser check the format (we still check again in PHP).هەر
nameـێک دەبێتە لە$_POSTـدا لە پەڕەی دواتر.type="password"خاڵ پیشان دەدات؛type="email"ڕێگە بە دەدات شێوازەکە بپشکنێت (هێشتا لە PHPـدا دووبارە دەیپشکنینەوە).- Lineدێڕی 21
The file input;
accept="image/*"only suggests images in the file window — it is not a security check.خانەی ؛
accept="image/*"تەنها لە پەنجەرەی وێنە پێشنیار دەکات — پشکنینی نییە.- Lineدێڕی 23
The Register button.
دوگمەی Register.
A midterm task with a full solutionئەرکێکی تاقیکردنەوەی نیوەی وەرز بە چارەسەری تەواوەوە
Worked solution, part 2: Profile.phpچارەسەری کارپێکراو، بەشی 2: Profile.php
<?php
// Profile.php - receives the data from Register.php
$message = "";
$errors = [];
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
$message = "Please use the registration form first.";
} else {
// 1. Read the inputs and remove unnecessary white space
$username = trim($_POST["username"] ?? "");
$email = trim($_POST["email"] ?? "");
$password = trim($_POST["password"] ?? "");
$image = $_FILES["avatar"] ?? null;
// 2. Is any input missing?
$noImage = $image === null || $image["error"] === UPLOAD_ERR_NO_FILE;
if ($username === "" || $email === "" || $password === "" || $noImage) {
$message = "Please fill out all inputs.";
} else {
// 3. Validate every input
if (!preg_match("/^[A-Za-z0-9_]{3,20}$/", $username)) {
$errors[] = "Username: use 3 to 20 letters, digits or _.";
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "The email address is not valid.";
}
if (strlen($password) < 8) {
$errors[] = "The password needs at least 8 characters.";
}
if ($image["error"] !== UPLOAD_ERR_OK) {
$errors[] = "The image could not be uploaded.";
} else {
$ext = strtolower(pathinfo($image["name"], PATHINFO_EXTENSION));
if (!in_array($ext, ["jpg", "jpeg", "png", "gif"])) {
$errors[] = "The image must be JPG, PNG or GIF.";
} elseif ($image["size"] > 2 * 1024 * 1024) {
$errors[] = "The image must be smaller than 2 MB.";
} elseif (getimagesize($image["tmp_name"]) === false) {
$errors[] = "The file is not a real image.";
}
}
// 4. No errors: save the image under a new, safe name
if (count($errors) === 0) {
$newName = "uploads/" . bin2hex(random_bytes(8)) . "." . $ext;
if (!move_uploaded_file($image["tmp_name"], $newName)) {
$errors[] = "The image could not be saved.";
}
}
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Profile</title>
</head>
<body>
<?php
if ($message !== "") {
echo "<p>" . $message . "</p>";
} elseif (count($errors) > 0) {
echo "<ul>";
foreach ($errors as $error) {
echo "<li>" . $error . "</li>";
}
echo "</ul>";
} else {
echo "<table border=\"1\">";
echo "<tr><th>Username</th><th>Password</th><th>Email</th><th>Avatar</th></tr>";
echo "<tr>";
echo "<td>" . htmlspecialchars($username) . "</td>";
echo "<td>" . str_repeat("*", strlen($password)) . "</td>";
echo "<td>" . htmlspecialchars($email) . "</td>";
echo "<td><img src=\"" . $newName . "\" width=\"80\" alt=\"Avatar\"></td>";
echo "</tr>";
echo "</table>";
}
?>
</body>
</html>Explain the codeڕوونکردنەوەی کۆدەکە
- Lineدێڕی 6-7
Somebody opened
Profile.phpdirectly, without the form.کەسێک بەبێ ڕاستەوخۆ
Profile.phpـی کردەوە.- Lineدێڕی 10-13
Read every input.
?? ""avoids warnings when a key is missing, andtrim()removes the extra spaces.هەموو خانەیەک بخوێنەوە.
?? ""ڕێگە لە دەگرێت کاتێک نەبێت وtrim()زیادەکان لادەبات.- Lineدێڕی 16-18
If any input is empty (error code
UPLOAD_ERR_NO_FILEmeans no picture was chosen), set only the message — no table.ئەگەر هەر خانەیەک بەتاڵ بێت (کۆدی
UPLOAD_ERR_NO_FILEواتە هیچ وێنەیەک هەڵنەبژێردراوە)، تەنها پەیامەکە دابنێ — بێ .- Lineدێڕی 21-29
Validate username (letters, digits,
_), email (filter_var) and password length. Every problem is added to$errors.(پیت، ژمارە،
_)، (filter_var) و درێژیی بکە. هەر کێشەیەک دەخرێتە ناو$errors.- Lineدێڕی 30-41
Check the upload: no upload error, an allowed extension, at most 2 MB, and
getimagesize()proves it is really an image.بپشکنە: هیچ نییە، ڕێگەپێدراو، زۆرترین 2 MB و
getimagesize()دەیسەلمێنێت کە بە ڕاستی وێنەیە.- Lineدێڕی 44-48
Only when everything is valid, move the temporary file into the
uploadsfolder under a new random name (so a user cannot overwrite another file). Create theuploadsfolder first.تەنها کاتێک هەموو شتێک دروستە، بگوازەرەوە بۆ
uploadsبە ناوێکی هەڕەمەکیی نوێ (تا نەتوانێت تر بسڕێتەوە). سەرەتاuploadsدروست بکە.- Lineدێڕی 61-68
Message, or the list of problems…
پەیامەکە، یان لیستی کێشەکان…
- Lineدێڕی 69-78
…or the table. User text goes through
htmlspecialchars(); the password is shown as stars.…یان . دەقی بە
htmlspecialchars()ـدا تێدەپەڕێت؛ وەک ئەستێرە پیشان دەدرێت.
A midterm task with a full solutionئەرکێکی تاقیکردنەوەی نیوەی وەرز بە چارەسەری تەواوەوە
Test your answerچارەسەرەکەت تاقی بکەرەوە
Here is what Profile.php sends back in four situations (tested with PHP 8.5):
ئەمە ئەوەیە کە Profile.php لە چوار دۆخدا دەینێرێتەوە (بە PHP 8.5 تاقی کراوەتەوە):
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<table border="1"><tr><th>Username</th><th>Password</th><th>Email</th><th>Avatar</th></tr><tr><td>it_stage_2</td><td>***********</td><td>it_stage2@example.com</td><td><img src="uploads/3f9a1c0b7d2e4a65.png" width="80" alt="Avatar"></td></tr></table>The spaces around the username were removed by trim(). The image name is random, so yours will differ.
دەوری بە trim() لابران. ناوی وێنەکە هەڕەمەکییە، بۆیە هی تۆ جیاواز دەبێت.
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<p>Please fill out all inputs.</p>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<ul><li>Username: use 3 to 20 letters, digits or _.</li><li>The email address is not valid.</li><li>The password needs at least 8 characters.</li><li>The file is not a real image.</li></ul>HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<p>Please use the registration form first.</p>The output challenge: 20 questionsتەحەدای دەرخستە: 20 پرسیار
Students of this course kept a set of short code snippets with their answers, to quiz each other: “What does this code print?” Here are all twenty, grouped by topic. Read each snippet, decide before you choose an answer, and only then check. Every answer was run on PHP 8.5.
خوێندکارانی ئەم کۆرسە کۆمەڵێک پارچە کۆدی کورتیان لەگەڵ چارەسەرەکانیان هەڵگرتبوو، بۆ ئەوەی یەکتر تاقی بکەنەوە: «ئەم کۆدە چی چاپ دەکات؟» ئەمە هەر بیستیانە، بەپێی بابەت گرووپ کراون. هەر پارچەیەک بخوێنەوە، پێش هەڵبژاردنی وەڵامێک بڕیار بدە و تەنها دوای ئەوە بیپشکنە. هەموو چارەسەرێک لەسەر PHP 8.5 جێبەجێ کراوە.
The output challenge: 20 questionsتەحەدای دەرخستە: 20 پرسیار
Round 1: echo, print and constantsقۆناغی 1: echo، print و نەگۆڕەکان
<?php
$result = print(null);
echo $result;<?php
$result = print("hey");
print $result;<?php
$result = print(null);
print $result;<?php
define("w4", 3.14);
echo "w4";The output challenge: 20 questionsتەحەدای دەرخستە: 20 پرسیار
Round 2: switchقۆناغی 2: switch
<?php
$x = 5;
switch ($x) {
case 1:
echo "1";
case 5:
continue;
echo "5";
case 6:
echo "6";
}<?php
$x = 5;
switch ($x) {
case 1:
echo "1";
case 5:
echo "5";
break; break; break; break;
default:
echo "Default";
break; break; break;
}
echo "<br />" . $x;The output challenge: 20 questionsتەحەدای دەرخستە: 20 پرسیار
Round 3: loopsقۆناغی 3: خولەکان
<?php
$x = 10;
do {
echo $x;
$x++;
} while ($x <= 5);
echo "<br />" . $x;<?php
while (true)
if (true)
break;The output challenge: 20 questionsتەحەدای دەرخستە: 20 پرسیار
Round 4: functionsقۆناغی 4: کردارەکان
<?php
function x() {
return "Hey";
echo "How";
}
echo x();<?php
function addFive($num) {
return $num += 5;
}
echo addfivE(5);<?php
function addFive($num) {
return $num += 5;
}
function addSix(&$num) {
return $num += 6;
}
echo addsix(5);<?php
function addFive($num) {
return $num += 5;
}
function addSix(&$num) {
return $num += 6;
}
echo addsix(ADDFive(5));The output challenge: 20 questionsتەحەدای دەرخستە: 20 پرسیار
Round 5: function names and scopeقۆناغی 5: ناوی کردارەکان و مەودا
<?php
function a() {}
function A() {}
echo "Done";<?php
$x = 5;
test();
function test() {
global $x = 7;
echo $x;
}
echo $x;<?php
$x = 5;
test();
function test() {
global $x, $y;
echo $x;
}
echo $x;The output challenge: 20 questionsتەحەدای دەرخستە: 20 پرسیار
Round 6: arraysقۆناغی 6: ڕیزەکەکان
<?php
$a = []; // the same as: $a = array();
echo $a;<?php
$a = []; // the same as: $a = array();
$a[0] = "Aram";
$a[1] = "Shilan";
echo $a[1];<?php
// $a = []; <- this line is commented out
$a[0] = "Aram";
$a[1] = "Shilan";
echo $a[0];<?php
$a['A'] = "Aram";
$a[1] = "Shilan";
echo "$a[A]";
echo "<br />";
echo "$a[1]";<?php
$mixed = array(8 => "Karwan", 'TR' => 'Shilan', 'Aram', 'Dilan');
echo $mixed[10];
echo $mixed[8];
echo $mixed[9];
echo $mixed['TR'];Using AI tools to make practice questionsبەکارهێنانی ئامرازەکانی ژیریی دەستکرد بۆ دروستکردنی پرسیاری ڕاهێنان
One student of this course asked ChatGPT (an AI chatbot) to write extra exam-style “What is the output?” questions. Only the two requests (prompts) were saved, not the questions. Cleaned up, they asked for:
یەکێک لە خوێندکارانی ئەم کۆرسە داوای لە ChatGPT ( ) کرد پرسیاری زیادەی جۆری تاقیکردنەوە بنووسێت: « چییە؟». تەنها دوو داواکارییەکە (prompt) هەڵگیرابوون، نەک پرسیارەکان. بە ڕێکخراوی، داوای ئەمانەیان کردبوو:
- Ten complex and challenging output questions for an exam paper that mix multidimensional arrays with normal functions, the
globalkeyword and functions such asstrlen(),count()andstrpos(). - Five complex and challenging output questions that use only
for,whileanddo ... whileloops.
- دە پرسیاری ئاڵۆز و قورسی بۆ پەڕەی تاقیکردنەوە کە لەگەڵ ئاسایی، وشەی کلیلیی
globalو وەکstrlen()،count()وstrpos()تێکەڵ بکەن. - پێنج پرسیاری ئاڵۆز و قورسی کە تەنها
for،whileوdo ... whileبەکاربهێنن.
Using a chatbot this way can be a good study idea — if you use it carefully. Follow these rules:
بەکارهێنانی بەم شێوەیە دەتوانێت بیرۆکەیەکی باش بێت بۆ خوێندن — ئەگەر بە وریاییەوە بەکاری بهێنیت. ئەم یاسایانە پەیڕەو بکە:
- AI can be wrong. Chatbots sometimes give the wrong output, mix old and new PHP versions, or invent functions that do not exist. Run every question in XAMPP and trust PHP, not the chatbot.
- Ask for the questions without the answers. Solve them on paper first, then run the code. Reading ready answers teaches you very little.
- Practice, not graded work. Use it to practise. Do not hand in AI-written homework as your own, and never use it during an exam. Follow your teacher's and your university's rules.
- Protect people's data. Do not paste exam papers, classmates' work, names, marks or passwords into a chatbot.
- Ask it to explain your mistakes, then check the explanation in the PHP manual (php.net) or in these lectures.
- Say exactly what you want: your level, PHP 8, which topics, how many questions, and "questions first, answers later".
- دەتوانێت هەڵە بکات. هەندێک جار هەڵە دەدەن، وەشانی کۆن و نوێی PHP تێکەڵ دەکەن، یان وا دادەهێنن کە بوونیان نییە. هەموو پرسیارێک لە جێبەجێ بکە و متمانە بە PHP بکە، نەک بە .
- داوای پرسیارەکان بکە بەبێ چارەسەرەکان. سەرەتا لەسەر کاغەز چارەسەریان بکە، پاشان کۆدەکە جێبەجێ بکە. خوێندنەوەی چارەسەری ئامادە زۆر کەم فێرت دەکات.
- ڕاهێنان، نەک کاری نمرەدار. بۆ ڕاهێنان بەکاری بهێنە. ئەرکی ماڵەوەی نووسراو بە وەک هی خۆت مەدە و هەرگیز لە کاتی تاقیکردنەوەدا بەکاری مەهێنە. یاساکانی مامۆستاکەت و زانکۆکەت پەیڕەو بکە.
- خەڵک بپارێزە. پەڕەی تاقیکردنەوە، کاری هاوپۆلەکانت، ناو، نمرە یان مەخەرە ناو .
- داوای لێ بکە هەڵەکانت ڕوون بکاتەوە، پاشان ڕوونکردنەوەکە لە ڕێنمایی PHP (php.net) یان لەم وانانەدا بپشکنە.
- ڕێک بڵێ چیت دەوێت: ئاستەکەت، PHP 8، کام بابەتەکان، چەند پرسیار و «سەرەتا پرسیار، دواتر چارەسەر».
I am a second-year student learning PHP 8. Write 5 "What is the output?" questions
for practice. Each question must use a multidimensional array, one function
that uses the global keyword, and the string functions strlen() and strpos().
Use only features that work in PHP 8. Give me ONLY the questions first.
I will send you my answers, and then you check them and explain my mistakes.How to use AI as a coach, not a crutch: ask it to explain your mistakes, write the code yourself, and do not trust every answer.
چۆن وەک ڕاهێنەر بەکاربهێنیت، نەک وەک گۆچان: داوای لێبکە هەڵەکانت ڕوون بکاتەوە، کۆدەکە خۆت بنووسە و متمانە بە هەموو وەڵامێک مەکە.
Five rules for learning to code with AI the right way
پێنج یاسا بۆ ئەوەی بە شێوەی دروست و بە یارمەتیی فێری کۆدنووسین ببیت.
Using AI tools to make practice questionsبەکارهێنانی ئامرازەکانی ژیریی دەستکرد بۆ دروستکردنی پرسیاری ڕاهێنان
Five practice questions, checked with PHPپێنج پرسیاری ڕاهێنان، پشکنراو بە PHP
Below are five questions of the kinds the two prompts asked for. They were written for this lecture and every output was checked with PHP 8.5 — exactly what you should do with questions a chatbot gives you. Questions 1–3 follow the first prompt (arrays, functions, global, string functions), questions 4–5 the second (loops only).
لە خوارەوە پێنج پرسیار هەیە لەو جۆرانەی دوو promptـەکە داوایان کردبوو. بۆ ئەم وانەیە نووسراون و هەموو بە PHP 8.5 پشکنراوە — ڕێک ئەوەی کە دەبێت لەگەڵ ئەو پرسیارانەی پێت دەدات بیکەیت. پرسیارەکانی 1–3 پەیڕەوی یەکەم prompt دەکەن (، ، global، )، پرسیارەکانی 4–5 دووەم (تەنها ).
Arrays, global, count() and strlen(): what is printed?
، global، count() و strlen(): چی چاپ دەکرێت؟
<?php
$classes = [
"A" => ["Aram", "Shilan", "Karwan"],
"B" => ["Hana", "Rezan"],
];
$total = 0;
function countStudents($group) {
global $classes, $total;
$total += count($classes[$group]);
return strlen($classes[$group][0]);
}
echo countStudents("A") . "-";
echo countStudents("B") . "-";
echo $total;Show answerوەڵامەکە پیشان بدە
4-4-5
Call 1: $total becomes 0 + 3 = 3 and the function returns strlen("Aram") = 4. Call 2: $total becomes 3 + 2 = 5 and it returns strlen("Hana") = 4. Then $total is printed.
بانگکردنی 1: $total دەبێتە 0 + 3 = 3 و strlen("Aram") = 4 دەگەڕێنێتەوە. بانگکردنی 2: $total دەبێتە 3 + 2 = 5 و strlen("Hana") = 4 دەگەڕێنێتەوە. پاشان $total چاپ دەکرێت.
A 2-D array and strpos(): what is printed?
و strpos(): چی چاپ دەکرێت؟
<?php
$data = [
["name" => "Dilan", "city" => "Slemani"],
["name" => "Soran", "city" => "Hewler"],
];
function findCity($people, $letter) {
foreach ($people as $person) {
$pos = strpos($person["city"], $letter);
if ($pos !== false) {
return $person["name"] . ":" . $pos;
}
}
return "none";
}
echo findCity($data, "e") . " ";
echo findCity($data, "w") . " ";
echo findCity($data, "z");Show answerوەڵامەکە پیشان بدە
Dilan:2 Soran:2 none
Positions start at 0. "Slemani": S=0, l=1, e=2, so Dilan:2. "w" is not in "Slemani" but is in "Hewler" at position 2, so Soran:2. "z" is nowhere, so none. !== false matters: a match at position 0 would otherwise look like “not found”.
شوێنەکان لە 0ـەوە دەست پێدەکەن. "Slemani": S=0، l=1، e=2، بۆیە Dilan:2. "w" لە "Slemani"ـدا نییە بەڵام لە "Hewler"ـدا لە شوێنی 2دایە، بۆیە Soran:2. "z" لە هیچ شوێنێک نییە، بۆیە none. !== false گرنگە: ئەگەر نا یەکگرتنەوەیەک لە شوێنی 0 وەک «نەدۆزرایەوە» دەردەکەوێت.
Nested arrays and count(..., COUNT_RECURSIVE): what is printed?
ناوەکی و count(..., COUNT_RECURSIVE): چی چاپ دەکرێت؟
<?php
$matrix = [[1, 2, 3], [4, 5], [6]];
$x = 0;
function addRow($row) {
global $x;
foreach ($row as $n) {
$x += $n;
}
return count($row);
}
echo addRow($matrix[0]) + addRow($matrix[2]);
echo " " . $x;
echo " " . count($matrix, COUNT_RECURSIVE);Show answerوەڵامەکە پیشان بدە
4 12 9
addRow([1,2,3]) adds 6 to $x and returns 3; addRow([6]) adds 6 more ($x = 12) and returns 1. 3 + 1 = 4. COUNT_RECURSIVE counts the 3 inner arrays and their 6 values = 9.
addRow([1,2,3]) 6 دەخاتە سەر $x و 3 دەگەڕێنێتەوە؛ addRow([6]) 6ی تر زیاد دەکات ($x = 12) و 1 دەگەڕێنێتەوە. 3 + 1 = 4. COUNT_RECURSIVE 3 ناوەکییەکە و 6 دەژمێرێت = 9.
for with a step of 3, and while counting down: what is printed?
for بە هەنگاوی 3 و while کە بەرەو خوار دەژمێرێت: چی چاپ دەکرێت؟
<?php
for ($i = 1; $i <= 10; $i += 3) {
echo $i;
}
echo "|";
$j = 5;
while ($j > 0) {
$j -= 2;
echo $j;
}Show answerوەڵامەکە پیشان بدە
14710|31-1
The for loop prints 1, 4, 7, 10 (13 is too big). The while loop subtracts before printing: 5→3, 3→1, 1→-1, then -1 > 0 is false.
1، 4، 7، 10 چاپ دەکات (13 زۆر گەورەیە). پێش چاپکردن کەم دەکاتەوە: 5←3، 3←1، 1←-1، پاشان -1 > 0 هەڵەیە.
continue inside do ... while, and a for loop with two variables: what is printed?
continue لە ناو do ... whileـدا و بە دوو : چی چاپ دەکرێت؟
<?php
$k = 0;
do {
$k++;
if ($k == 2) {
continue;
}
echo $k;
} while ($k < 4);
echo "|";
for ($a = 0, $b = 3; $a < $b; $a++, $b--) {
echo $a . $b;
}Show answerوەڵامەکە پیشان بدە
134|0312
In do ... while, continue jumps to the condition check, not to the top: 1 is printed, 2 is skipped, then 3 and 4. In the for loop, $a goes up and $b goes down: 03, 12, then 2 < 1 is false.
لە do ... whileـدا، continue باز دەدات بۆ پشکنینی ، نەک بۆ سەرەوە: 1 چاپ دەکرێت، 2 دەپەڕێنرێت، پاشان 3 و 4. لە ، $a بەرز دەبێتەوە و $b نزم دەبێتەوە: 03، 12، پاشان 2 < 1 هەڵەیە.
Next steps after this courseهەنگاوەکانی دوای ئەم کۆرسە
A first look at object-oriented PHP: what a class is, properties, constructors, creating objects and calling methods with the -> arrow.
ناساندنێکی سەرەتایی بۆ لە : چییە، ، constructor، دروستکردنی و بانگکردنی بە ->.
Watch 0:00–26:28: classes, properties, objects and methods
لە 0:00 تا 26:28 سەیر بکە: ، ، و .
Final checklistلیستی پشکنینی کۆتایی
Before the exam, make sure you can do each of these without notes:
پێش تاقیکردنەوە، دڵنیابە کە دەتوانیت هەر یەکێک لەمانە بەبێ تێبینی بکەیت:
- Explain internet vs Web, client vs server, URL parts, DNS and the HTTP request/response cycle.
- Start XAMPP and run a page from
htdocs. - Write variables, strings, operators,
if/switchand the four loops, and predict their output. - Write functions with parameters, defaults and references; use indexed, associative and multidimensional arrays and sort them.
- Build a form, read it with
$_GET/$_POST, validate it, escape the output, and handle a file upload. - Create a table, then INSERT, SELECT, UPDATE and DELETE from PHP with prepared statements.
- Use cookies and sessions, and build register / login / logout with
password_hash()andpassword_verify(). - Explain what an API is, and turn PHP arrays into JSON and back.
- جیاوازیی و ، و ، بەشەکانی ، و سووڕی / HTTP ڕوون بکەیتەوە.
- دەست پێبکەیت و پەڕەیەک لە
htdocsـەوە جێبەجێ بکەیت. - ، ، ،
if/switchو چوار بنووسیت و پێشبینی بکەیت. - بە ، و بنووسیت؛ ، و بەکاربهێنیت و ڕیزیان بکەیت.
- دروست بکەیت، بە
$_GET/$_POSTبیخوێنیتەوە، بکەیت، پارێزراو بکەیت و بەڕێوە ببەیت. - دروست بکەیت، پاشان بە لە PHPـەوە INSERT، SELECT، UPDATE و DELETE بکەیت.
- و بەکاربهێنیت و / / بە
password_hash()وpassword_verify()دروست بکەیت. - ڕوون بکەیتەوە چییە و PHP بکەیت بە JSON و بە پێچەوانەوە.
What is the difference between include and require when the file is missing?جیاوازیی include و require چییە کاتێک فایلەکە نییە؟
include gives a warning and the script continues; require stops with a fatal error.
include دەدات و بەردەوام دەبێت؛ require بە دەوەستێت.
Why must header("Location: ...") and setcookie() come before any output?بۆچی دەبێت header("Location: ...") و setcookie() پێش هەر دەرخستەیەک بن؟
Both send HTTP headers, and headers must travel before the page body. After the first output PHP can no longer send them (“headers already sent”).
هەردووکیان دەنێرن و دەبێت پێش لاشەی پەڕەکە بڕۆن. دوای یەکەم PHP ناتوانێت بیاننێرێت («headers already sent»).
What protects a page against XSS, and what protects a database against SQL injection?کام دوو ڕێگا پەڕەیەک لە XSS و بنکەدراوەیەک لە تێخزاندنی SQL دەپارێزن؟
htmlspecialchars() when printing user text; prepared statements (mysqli_prepare() / PDO prepare()) for SQL.
htmlspecialchars() لە کاتی چاپکردنی دەقی ؛ (mysqli_prepare() / prepare()ـی PDO) بۆ SQL.
Where are cookies stored and where are sessions stored?کووکییەکان لە کوێ و سێشنەکان لە کوێ هەڵدەگیرێن؟
Cookies in the visitor's browser; session data on the server (the browser keeps only the session ID).
لە سەردانکەردا؛ لەسەر ( تەنها هەڵدەگرێت).
Which loop always runs at least once, and which statement skips only the current turn?کام خول هەمیشە لانیکەم جارێک جێبەجێ دەبێت و کام ڕستە تەنها خولانەوەی ئێستا دەپەڕێنێت؟
do ... while; continue.
do ... while؛ continue.
How do you store a password safely?چۆن تێپەڕەوشەیەک بە سەلامەتی هەڵدەگریت؟
With password_hash($password, PASSWORD_DEFAULT); check it later with password_verify(). Never store plain text or md5().
بە password_hash($password, PASSWORD_DEFAULT)؛ دواتر بە password_verify() بیپشکنە. هەرگیز دەقی ئاسایی یان md5() هەڵمەگرە.
Videoڤیدیۆ
Watch a videoسەیری ڤیدیۆیەک بکە
A video that viewers liked a lot and praised in their comments, chosen for this lesson.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.
How to create a function, send values in with arguments, and get a result back with return, with a short practice example.
چۆن دروست بکەیت، بە بنێریتە ناوی و بە return ئەنجامێک لێی وەربگریتەوە، لەگەڵ ڕاهێنانێکی کورت.
Watch 0:00–3:26:07; our own lectures cover the database part
لە 0:00 تا 3:26:07 سەیر بکە؛ بەشی لە وانەکانی خۆماندا ڕوون کراوەتەوە.
Lesson complete!وانەکە تەواو بوو!
Well done. Review the key terms, then go on to the next lesson.دەستخۆش. سەیرێکی زاراوە سەرەکییەکان بکەرەوە، پاشان بڕۆ بۆ وانەی داهاتوو.
Key termsزاراوە سەرەکییەکان
Related lecturesوانە پەیوەندیدارەکان
- The Internet and the Webئینتەرنێت و وێب
- XAMPP: Your Own Local Web ServerXAMPP: ڕاژەکاری وێبی ناوخۆیی خۆت
- Introduction to PHPسەرەتایەک بۆ PHP
- Loops: while, do...while, for, foreach, break and continueخولەکان: while و do...while و for و foreach و break و continue
- Arrays in PHPڕیزەکەکان لە PHPـدا
- Form Validationپشتڕاستکردنەوەی فۆرم
- Uploading Filesبارکردنی فایل
- Building a CRUD Application with PHP and MySQLدروستکردنی بەرنامەیەکی CRUD بە PHP و MySQL
- Sessionsسێشنەکان
- Web APIs and JSONAPIـی وێب و JSON
References and further readingسەرچاوەکان و خوێندنەوەی زیاتر
- PHP Manual
- PHP Manual: Language reference
- PHP Manual: Handling file uploads
- PHP Manual: filter_var()
- PHP Manual: htmlspecialchars()
- PHP Manual: move_uploaded_file()
- PHP Manual: mysqli_num_rows()
- PHP Manual: password_hash()
- PHP Manual: ucwords()
- PHP Manual: trim()
- MDN: Your first form
- SQLite: LIMIT and OFFSET in SELECT
- Apache Friends: XAMPP
- OWASP Top 10
This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.