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⁩ پرسیار و چۆنیەتی بەکارهێنانی ئامرازەکانی بۆ ڕاهێنان بە بەرپرسیارێتی.

48 min read48 خولەک خوێندنەوە · 41 stepsهەنگاو

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⁩ بەشەی خوارەوە.
  1. Do one chapter screen at a time. Answer the quick questions before you open the full lecture.
  2. When you get a question wrong, follow the link and read that part again — then try the question once more.
  3. Run every piece of code in XAMPP. If your result differs from the page, find out why.
  4. Say the important words out loud (see Words you should know).
  1. هەر جارە یەک شاشەی بەش بکە. پێش کردنەوەی وانە تەواوەکە وەڵامی پرسیارە خێراکان بدەرەوە.
  2. کاتێک پرسیارێکت بە هەڵە وەڵام دایەوە، بەدوای بڕۆ و ئەو بەشە دووبارە بخوێنەوە — پاشان جارێکی تر پرسیارەکە تاقی بکەرەوە.
  3. هەموو پارچە کۆدێک لە جێبەجێ بکە. ئەگەر ئەنجامەکەت جیاواز بوو لەوەی پەڕەکە، بزانە بۆچی.
  4. وشە گرنگەکان بە دەنگی بەرز بڵێ (بڕوانە ئەو وشانەی دەبێت بیانزانیت).
A map of the ten chapters of the course, numbered 1 to 10 in two rows joined by arrows: How the Web Works, Your Development Environment, HTML Review, PHP Basics, Decisions and Loops, Functions and Arrays, Forms and User Input, Databases with PHP, Cookies Sessions and Logins, and APIs and Review. Colours group them: the web and your tools, the PHP language, real web applications, next steps.نەخشەی دە بەشەکەی کۆرسەکە، ژمارە 1 تا 10 لە دوو ڕیزدا کە بە تیر بەیەکەوە بەستراون: وێب چۆن کار دەکات، ژینگەی پەرەپێدان، پێداچوونەوەی HTML، بنەماکانی PHP، بڕیاردان و دووبارەکردنەوە، کردار و ڕیزەک، فۆرم و نێوخستەی بەکارهێنەر، بنکەدراوە لەگەڵ PHP، کووکی و سێشن و چوونەژوورەوە و API و پێداچوونەوە. ڕەنگەکان کۆیان دەکەنەوە: وێب و ئامرازەکانت، زمانی PHP، بەرنامەی ڕاستەقینەی وێب، هەنگاوی داهاتوو.
The whole course as a path: each chapter builds on the one before it.هەموو کۆرسەکە وەک ڕێگایەک: هەر بەشێک لەسەر بەشی پێشووتری بنیات دەنرێت.CêIT

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 پیشان دەدات.

The six modules of the course slides and where they are 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, phpLiteAdmin⁦SQL92⁩، سەکۆکان، مێژوو، ، ، ، هەستیاری بە قەبارەی پیت، 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 دروست دەکرێت.

Quick check

پشکنینی خێرا

Quick checkپشکنینی خێراAre the Internet and the Web the same thing?ئایا و هەمان شتن؟

Quick checkپشکنینی خێراIn https://www.example.com/shop/index.php?id=7, which part is the domain name?لە https://www.example.com/shop/index.php?id=7ـدا، کام بەش ؟

Quick checkپشکنینی خێراWhat does DNS do? چی دەکات؟

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\htdocs and open them through http://localhost/.... Double-clicking a .php file 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، M⁦ariaDB/MySQL⁩، PHP و Perl.
  • Apache (و MySQL بۆ ) لە XAMPPـدا دەست پێبکە، پاشان http://localhost بکەرەوە.
  • لە C:\xampp\htdocsـدا پاشەکەوت بکە و لە ڕێگەی http://localhost/...ـەوە بیانکەرەوە. دوو کرتە لەسەر .php PHP جێبەجێ ناکات.
  • ئەگەر ⁦80⁩ گیرابێت ( تر بەکاری دەهێنێت)، Apache دەست پێناکات: ئەو دابخە یان Apache بگوازەرەوە بۆ تر وەک ⁦8080⁩ (http://localhost:8080).
  • کۆد لە یان وەک ⁦VS Code⁩ یان NetBeans بنووسە.

Quick check

پشکنینی خێرا

Quick checkپشکنینی خێراYou saved test.php in htdocs. How do you run it?test.phpـت لە htdocsـدا پاشەکەوت کرد. چۆن جێبەجێی دەکەیت؟

Quick checkپشکنینی خێراWhat do the two letters P in XAMPP stand for?دوو پیتی P لە واتای چین؟

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>; colspan and rowspan join 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 name attribute of a control becomes the key that PHP reads: name="email" → $_POST["email"]. File uploads also need enctype="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

پشکنینی خێرا

Quick checkپشکنینی خێراWhich attribute decides the key you use in $_POST?کام ئەو دیاری دەکات کە لە $_POSTـدا بەکاری دەهێنیت؟

Quick checkپشکنینی خێراWhich tag starts a new row in a table?کام نوێ لە دەست پێدەکات؟

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 <?php and ?>; every statement ends with ;. Comments: //, # and /* ... */.
  • echo and print send output; print returns 1 and takes one argument, echo can 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) or const PI = 3.14; — no $, cannot change. Scope: local inside functions, global outside (global, $GLOBALS), and static variables 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 دەنێرن؛ print 1 دەگەڕێنێتەوە و یەک وەردەگرێت، echo دەتوانێت چەندین وەربگرێت.
  • بە $ دەست پێدەکەن و دوای ئەوە پیتێک یان _ دێت و . PHP : جۆرەکە لە دێت.
  • : ، ، ، ، ، ، (و ).
  • : define("PI", 3.14) یان const PI = 3.14; — بێ $، ناگۆڕدرێن. : ناوخۆیی لە ناو ، گشتی لە دەرەوە (global، $GLOBALS) و دەپارێزن.
  • : تاکەگوتە ڕێک وەک خۆی چاپ دەکات، جووتەگوتە تێدەخات؛ بە . پێکەوە دەلکێنرێن؛ بەسوود: strlen()، strtoupper()، ucwords()، strpos()، str_replace()، trim().
  • : (+ - * / % **)، (+=)، بەراوردکردن (== ، === و جۆر)، زیادکردن (++$x / $x++)، لۆجیکی (&& || !).

Quick check

پشکنینی خێرا

increment.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 5;
echo $x++ + ++$x;
Quick checkپشکنینی خێراWhat does this code print?ئەم کۆدە چی چاپ دەکات؟

compare.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
var_dump("5" == 5, "5" === 5);
Quick checkپشکنینی خێراWhat does var_dump() show?var_dump() چی پیشان دەدات؟

quotes.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$name = "Hana";
echo 'Hi $name';
Quick checkپشکنینی خێراWhat does this print?ئەمە چی چاپ دەکات؟

Chapter 5 — Making decisions and repeating codeبەشی 5 — بڕیاردان و دووبارەکردنەوەی کۆد

  • if, if ... else and if ... elseif ... else choose a path from a condition that is true or false.
  • switch compares one value with many cases. Without break, PHP falls through into the next case; default runs when nothing matches.
  • while checks first; do ... while runs the body at least once; for has start, condition and step in one line; foreach walks through an array.
  • break leaves the loop completely; continue skips 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

پشکنینی خێرا

break.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
for ($i = 1; $i <= 10; $i++) {
    if ($i % 4 == 0) {
        break;
    }
    echo $i;
}
Quick checkپشکنینی خێراWhat does this loop print?ئەم چی چاپ دەکات؟

switch.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$day = 2;
switch ($day) {
    case 1:
        echo "A";
    case 2:
        echo "B";
    case 3:
        echo "C";
        break;
    default:
        echo "D";
}
Quick checkپشکنینی خێراWhat does this switch print?ئەم switchـە چی چاپ دەکات؟

Quick checkپشکنینی خێراWhich loop always runs its body at least once?کام هەمیشە لانیکەم جارێک لاشەکەی جێبەجێ دەکات؟

Chapter 6 — Functions and arraysبەشی 6 — کردارەکان و ڕیزەکەکان

  • A function is written once with function name($param) { ... } and runs only when it is called. return sends 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; &$x passes 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/rsort sort values and renumber; asort/arsort sort by value and keep keys; ksort/krsort sort by key.
  • echo cannot show an array — use print_r() or var_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() بەکاربهێنە.

Quick check

پشکنینی خێرا

default.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
function add($a, $b = 10) {
    return $a + $b;
}
echo add(5);
Quick checkپشکنینی خێراWhat does this print?ئەمە چی چاپ دەکات؟

matrix.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$m = [[1, 2], [3, 4]];
echo $m[1][0];
Quick checkپشکنینی خێراWhat does this print?ئەمە چی چاپ دەکات؟

Quick checkپشکنینی خێراWhich function sorts an associative array by value, largest first, and keeps the keys?کام بەپێی ، گەورەترین لە سەرەتا، ڕیز دەکات و دەپارێزێت؟

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() and preg_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.
  • include gives a warning and continues if the file is missing; require stops with a fatal error. Use require_once for 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 with move_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() پاشەکەوتی بکە.

Quick check

پشکنینی خێرا

Quick checkپشکنینی خێراWhich method should a login form use? کام ڕێگا بەکاربهێنێت؟

escape.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo htmlspecialchars("<b>Hi</b>");
Quick checkپشکنینی خێراWhat does the browser receive from this code? چی لەم کۆدە وەردەگرێت؟

Quick checkپشکنینی خێراmissing.php does not exist. What is the difference between include "missing.php"; and require "missing.php";?missing.php بوونی نییە. جیاوازیی نێوان include "missing.php"; و require "missing.php"; چییە؟

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_INCREMENT numbers new rows for you.
  • SQL has groups of commands: DDL (CREATE, ALTER, DROP), DML (INSERT, UPDATE, DELETE) and DQL (SELECT with WHERE, 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 with password_verify() — never md5().
  • 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() نا.
  • پەڕەی هەیە بۆ دروستکردن، خوێندنەوە، نوێکردنەوە و سڕینەوەی . هەموو لە یەک هەڵدەگرێت و پێویستی بە نییە (، بێ ڕێکخستن).

Quick check

پشکنینی خێرا

Quick checkپشکنینی خێراWhich group does SELECT belong to?SELECT سەر بە کام گرووپە؟

Quick checkپشکنینی خێراWhat is the safe way to use a value from a form in an SQL query?ڕێگای سەلامەت چییە بۆ بەکارهێنانی لە SQLـدا؟

Quick checkپشکنینی خێراSELECT * FROM students ORDER BY id LIMIT 5 OFFSET 10 returns which rows?SELECT * FROM students ORDER BY id LIMIT 5 OFFSET 10 کام دەگەڕێنێتەوە؟

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 $_COOKIE from 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 with password_verify(), store the user's id in $_SESSION, protect pages by checking it, and log out with session_unset() and session_destroy().
  • HTTP لە نێوان هەموو شتێک لەبیر دەکات. و ڕێگای ئەوەن کە تۆی لەبیر بێت.
  • دەقێکی بچووکە کە لە دەمێنێتەوە و لەگەڵ هەموو دەگەڕێتەوە. setcookie(name, value, expire, ...) دەبێت پێش هەر بێت؛ لە دواترەوە لە $_COOKIEـدا دەیخوێنیتەوە؛ بە لە ڕابردوودا دەیسڕیتەوە.
  • لەسەر هەڵدەگرێت. لە سەرەوەی هەموو پەڕەیەک session_start() بانگ بکە، پاشان $_SESSION بەکاربهێنە. تەنها هەڵدەگرێت.
  • سیستەمی : بە password_hash() بکە، بە password_verify() بچۆ ژوورەوە، id-ـی لە $_SESSIONـدا هەڵبگرە، بە پشکنینی ئەو پەڕەکان بپارێزە و بە session_unset() و session_destroy() بکە.

Quick check

پشکنینی خێرا

Quick checkپشکنینی خێراWhere is session data stored? لە کوێ هەڵدەگیرێت؟

Quick checkپشکنینی خێراA page calls setcookie("lang", "ckb");. When does $_COOKIE["lang"] contain ckb?پەڕەیەک setcookie("lang", "ckb"); بانگ دەکات. $_COOKIE["lang"] کەی ckbـی تێدایە؟

Quick checkپشکنینی خێراWhich function checks a typed password against the stored hash?کام نووسراو لەگەڵ هاشە هەڵگیراوەکە بەراورد دەکات؟

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() and json_decode($json, true), and calls APIs with file_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

پشکنینی خێرا

json.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
echo json_encode(["city" => "Duhok", "rain" => false]);
Quick checkپشکنینی خێراWhat does this print?ئەمە چی چاپ دەکات؟

Quick checkپشکنینی خێراWhich status code means “created”, for example after a successful POST?کام واتە «دروست کرا»، بۆ نموونە دوای POSTـێکی سەرکەوتوو؟

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).

«نیوەی ئەوەیە بزانیت هەر شتێک ناوی چییە.» ئەم سێ لیستە لە سلایدەکانی کۆرسەکەوە هاتوون. هەموو وشەیەک لە وانەیەکدا هاتووە، بۆیە هەموو وشەیەک دەکرێت لە تاقیکردنەوەدا بپرسرێت. ئەو واتایانەی خوارەوە واتاکانی سلایدەکانن و ئەو شوێنانەی کۆن یان زۆر کورت بوون ڕاست کراونەتەوە (بڕوانە ئەو سندوقەی دوای ).

Part 1 — the web and the serverبەشی 1 — وێب و
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

Part 2 — the PHP languageبەشی 2 — زمانی
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 — بنکەدراوەکان و ئامرازەکان

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-configurationNothing to install or set up before you use it.پێش بەکارهێنان هیچ شتێک پێویستی بە دامەزراندن یان ڕێکخستن نییە.→
Self-containedNeeds 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چی ڕاست کرایەوە و تاقیکردنەوەی خۆت

ExerciseڕاهێنانSay them out loudبە دەنگی بەرز بیانڵێ

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وەڵامەکە پیشان بدە
Review questionsپرسیارەکانی پێداچوونەوە
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.

ExerciseڕاهێنانAbbreviation drillڕاهێنانی کورتکراوەکان

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.

ئەم هەشت ڕاهێنانە بە هەمان ڕیزبەندیی فێربوونی بابەتەکانن. پێش کردنەوەی چارەسەرەکە هەر یەکەیان تاقی بکەرەوە.

Exerciseڕاهێنان1. Install XAMPP1. XAMPP دابمەزرێنە

Install XAMPP, start Apache and MySQL, and open http://localhost.

دابمەزرێنە، Apache و MySQL دەست پێبکە و http://localhost بکەرەوە.

Show answerوەڵامەکە پیشان بدە
  1. 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 بهێڵەرەوە.

  2. Open the XAMPP Control Panel and press Start next to Apache and next to MySQL. Their names turn green.

    XAMPP بکەرەوە و لە تەنیشت Apache و MySQL دوگمەی Start دابگرە. ناوەکانیان سەوز دەبن.

  3. 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 بگۆڕە.

Success: Apache and MySQL are running (green), so their buttons now say Stop.سەرکەوتن: Apache و MySQL کار دەکەن (سەوز)، بۆیە دوگمەکانیان ئێستا دەڵێن Stop.Course material
Exerciseڕاهێنان2. Your first page2. یەکەم پەڕەت

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وەڵامەکە پیشان بدە
C:\xampp\htdocs\index.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<!DOCTYPE html>
<html>
<body>
<?php
echo "Hello world!";
?>
</body>
</html>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 5

echo sends 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⁩: گۆڕاوەکان، خولەکان، ڕیزەکەکان و کردارەکان

Exerciseڕاهێنان3. Variables3. کار لەگەڵ گۆڕاوەکان

Make a string, an integer and a float, and print all three.

، و دروست بکە و هەر سێکیان چاپ بکە.

Show answerوەڵامەکە پیشان بدە
variables.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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);
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() جۆر و پیشان دەدات — بۆ پشکنین باشە.

Exerciseڕاهێنان4. A loop — three versions4. خولێک — سێ وەشان

(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وەڵامەکە پیشان بدە
(a) 0 to 9(أ) 0 تا 9loop.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
for ($i = 0; $i <= 9; $i++) {
    echo $i . " ";
}
(b) skip 3(ب) 3 بپەڕێنەcontinue.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
for ($i = 0; $i <= 9; $i++) {
    if ($i == 3) {
        continue;   // skip 3, go on with 4
    }
    echo $i . " ";
}
(c) stop at 3(ج) لە 3 بوەستەbreak.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
for ($i = 0; $i <= 9; $i++) {
    if ($i == 3) {
        break;      // leave the loop completely
    }
    echo $i . " ";
}

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 و هەرچی دوای ئەوە هەرگیز چاپ ناکرێن.

Exerciseڕاهێنان5. An array5. کار لەگەڵ ڕیزەکێک

Store five names in an array and print them one under the other.

پێنج ناو لە هەڵبگرە و یەک لە ژێر یەکی تر چاپیان بکە.

Show answerوەڵامەکە پیشان بدە
names.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$names = ["Aram", "Shilan", "Karwan", "Dilan", "Rezan"];

foreach ($names as $name) {
    echo $name . "<br>";
}
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 4

foreach gives you each value in turn; <br> puts the next name on a new line in the browser.

foreach هەر بە نۆرە دەدات؛ <br> ناوی دواتر لە دەخاتە دێڕێکی نوێ.

Exerciseڕاهێنان6. A function6. نووسینی کردارێک

Write a function add($a, $b) that returns the sum, and call it three times.

بە ناوی add($a, $b) بنووسە کە کۆکەی دوو ژمارەکە بگەڕێنێتەوە و سێ جار بانگی بکە.

Show answerوەڵامەکە پیشان بدە
add.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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>";
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⁩: فۆرمێک و بنکەدراوەیەک

Exerciseڕاهێنان7. A form7. دروستکردنی فۆرمێک

Make a form with two text boxes and a submit button, and read the two values with $_POST.

بە دوو و دروست بکە و هەردوو بە $_POST بخوێنەوە.

Show answerوەڵامەکە پیشان بدە
form.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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>
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 name attributes become the keys of $_POST.

name دەبنە $_POST.

After sending an empty name (only spaces)دوای ناردنی ناوێکی بەتاڵ (تەنها بۆشایی)
Please fill in both boxes.
Exerciseڕاهێنان8. A database8. پاشەکەوتکردن لە بنکەدراوەیەکدا

Create a table in phpMyAdmin and save the form from exercise 7 into it.

لە دروست بکە و ڕاهێنانی 7ی تێدا پاشەکەوت بکە.

Show answerوەڵامەکە پیشان بدە
  1. In phpMyAdmin (http://localhost/phpmyadmin) create a database called practice.

    لە (http://localhost/phpmyadmin) بە ناوی practice دروست بکە.

  2. Open its SQL tab and run this statement (or build the same three columns with the Create table form):

    تابی SQLـی بکەرەوە و ئەم فەرمانە جێبەجێ بکە (یان هەمان سێ بە ⁦Create table⁩ دروست بکە):

visitors.sqlSQLRuns in the databaseلە ناو بنکەدراوە کار دەکات
CREATE TABLE visitors (
    id   INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(50) NOT NULL,
    city VARCHAR(50) NOT NULL
);
dbcon.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
// dbcon.php - opens the connection to the "practice" database
$con = mysqli_connect("localhost", "root", "", "practice");
mysqli_set_charset($con, "utf8mb4");
save.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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_once loads 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 جێبەجێی بکەیت:

sqlite-demo.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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";
}

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

پرسیاری نووسین

ExerciseڕاهێنانQ1. Types of arraysپ1. جۆرەکانی ڕیزەک

What are the types of arrays? Explain them and give an example of each.

جۆرەکانی چین؟ ڕوونیان بکەرەوە و نموونەیەک بۆ هەر یەکەیان بهێنەرەوە.

Show answerوەڵامەکە پیشان بدە
  1. Indexed array — PHP numbers the values for you, starting at 0.
  2. Associative array — you give every value a name (a key).
  3. Multidimensional array — an array that contains other arrays, like a table with rows and columns.
  1. — PHP خۆی ژمارە دەداتە ، لە 0ـەوە.
  2. — خۆت ناوێک () دەدەیتە هەر .
  3. — کە تری تێدایە، وەک بە و ستوونەکانەوە.
arrays.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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";

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:

تاقیکردنەوەکانی وێب زۆرجار هەمان نۆ جۆری پرسیار بەکار دەهێنن. هەر جۆرێک وەڵامێکی جیاوازی دەوێت، بۆیە سەرەتا بزانە کام جۆرەت لەبەردەمە. پێنجی یەکەم:

Question styles 1–5شێوازەکانی پرسیار، ١ تا ٥
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>ـی تێدا بێت.» (وەڵام)
Quick checkپشکنینی خێراA question says: "State the differences between static and dynamic websites." What is the best form for your answer?پرسیارێک دەڵێت: «جیاوازییەکانی نێوان نەگۆڕ و داینامیک بڵێ.» باشترین شێوە بۆ وەڵامەکەت چییە؟

Exam questions from the course bookپرسیارەکانی تاقیکردنەوە لە کتێبی کۆرسەکەوە

Nine question styles (continued)نۆ شێوازی پرسیار (بەردەوام)

Question styles 6–9شێوازەکانی پرسیار، ٦ تا ٩
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). تۆمارکردن بنووسە (تاقیگە)؛ دیزاین بکە کە هەر بەشێک لاپەڕەیەکی خۆی هەبێت (پڕۆژەکان).
Quick checkپشکنینی خێراIn a "true or false, and correct the false ones" question, the sentence is false. What do you write?لە پرسیارێکی « لەگەڵ ڕاستکردنەوەی هەڵەکان»دا ڕستەکە هەڵەیە. چی دەنووسیت؟

Exam questions from the course bookپرسیارەکانی تاقیکردنەوە لە کتێبی کۆرسەکەوە

True or Falseڕاست یان هەڵە

Quick checkپشکنینی خێراQ2. “ucwords() is used to convert words to lowercase.”پ2. «ucwords() بۆ گۆڕینی وشەکان بۆ پیتی بچووک بەکاردێت.»

ucwords.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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 string
Quick checkپشکنینی خێراQ3. “For connecting two or more strings in PHP we use the . symbol.”پ3. «بۆ دوو یان زیاتر لە PHPـدا هێمای . بەکاردەهێنین.»

concat.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$first = "Web";
$second = "Programming";

echo $first . " " . $second . "\n";

$title = $first;
$title .= " Programming";   // .= adds to the end of the string
echo $title;
Quick checkپشکنینی خێراQ4. “Functions in PHP will be executed when the page is loaded.”پ4. « لە PHPـدا کاتێک پەڕەکە دەکرێتەوە جێبەجێ دەبن.»

functions.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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 again
Quick checkپشکنینی خێراQ5. “The while loop executes the code once and after that it checks the condition.”پ5. « کۆدەکە جارێک جێبەجێ دەکات و دوای ئەوە دەپشکنێت.»

while.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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);
Quick checkپشکنینی خێراQ6. “The OFFSET property is used to limit the number of rows returned in the query.”پ6. «تایبەتمەندیی OFFSET بۆ سنووردارکردنی ژمارەی ئەو دەیانگەڕێنێتەوە بەکاردێت.»

limit.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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";
}

Exam questions from the course bookپرسیارەکانی تاقیکردنەوە لە کتێبی کۆرسەکەوە

Choose the correct answerهەڵبژاردەی دروست دیاری بکە

Quick checkپشکنینی خێراQ7. Which one is a correct variable name in PHP?پ7. کامیان ناوێکی دروستی لە PHPـدا؟

names.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$var = "valid";
$_count = 1;
$name2 = "also valid";
echo $var . " " . $_count . " " . $name2;
What PHP 8.5 says to $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
Quick checkپشکنینی خێراQ8. Which function removes white space from the beginning and end of a text?پ8. کام لە سەرەتا و کۆتایی دەقێک لادەبات؟

trim.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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 only
Quick checkپشکنینی خێراQ9. Which function returns the number of rows in the result of an executed query?پ9. کام ژمارەی ئەنجامی جێبەجێکراو دەگەڕێنێتەوە؟

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 دووبارە دروست کراونەتەوە:

Expected page 1: the “Registration Form” (Register.php)پەڕەی چاوەڕوانکراوی 1: «⁦Registration Form⁩» ⁦(Register.php)⁩
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.

Expected page 2: the table on Profile.phpپەڕەی چاوەڕوانکراوی 2: خشتەکەی سەر ⁦Profile.php⁩
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پلانی چارەسەرەکەت دابنێ

Flowchart: Register.php (a form with username, email, password and avatar, method post, enctype multipart/form-data) sends POST to Profile.php, which reads $_POST and $_FILES and trims the inputs. Decision: any input empty? Yes: show only the message Please fill out all inputs. No: decision all inputs valid? No: show the list of problems, no table. Yes: save the image and show the table.نەخشەی ڕەوت: Register.php (فۆرمێک بە username، email، password و avatar، method post، enctype multipart/form-data) بە POST دەنێرێت بۆ Profile.php، کە $_POST و $_FILES دەخوێنێتەوە و trim بۆ خانەکان دەکات. بڕیار: خانەیەک بەتاڵە؟ بەڵێ: تەنها پەیامی Please fill out all inputs. پیشان بدە. نەخێر: بڕیار: هەموو خانەکان دروستن؟ نەخێر: لیستی کێشەکان پیشان بدە، بێ خشتە. بەڵێ: وێنەکە پاشەکەوت بکە و خشتەکە پیشان بدە.
The plan for the answer: first check for empty inputs, then validate, and only then show the table.پلانی چارەسەرەکە: سەرەتا خانە بەتاڵەکان بپشکنە، پاشان بکە و تەنها ئەوکات پیشان بدە.CêIT

A midterm task with a full solutionئەرکێکی تاقیکردنەوەی نیوەی وەرز بە چارەسەری تەواوەوە

Worked solution, part 1: Register.phpچارەسەری کارپێکراو، بەشی ⁦1: Register.php⁩

Register.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<!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>
Explain the codeڕوونکردنەوەی کۆدەکە
Lineدێڕی 10

action sends the form to Profile.php; post hides the password from the URL; multipart/form-data is required for the file.

action دەنێرێت بۆ Profile.php؛ post لە دەشارێتەوە؛ multipart/form-data بۆ پێویستە.

Lineدێڕی 11-18

Each name becomes a key in $_POST on 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⁩

Profile.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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.php directly, without the form.

کەسێک بەبێ ڕاستەوخۆ Profile.phpـی کردەوە.

Lineدێڕی 10-13

Read every input. ?? "" avoids warnings when a key is missing, and trim() removes the extra spaces.

هەموو خانەیەک بخوێنەوە. ?? "" ڕێگە لە دەگرێت کاتێک نەبێت و trim() زیادەکان لادەبات.

Lineدێڕی 16-18

If any input is empty (error code UPLOAD_ERR_NO_FILE means 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 uploads folder under a new random name (so a user cannot overwrite another file). Create the uploads folder 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⁩ تاقی کراوەتەوە):

All four inputs correct (username “ it_stage_2 ” with spaces)هەر چوار خانەکە دروستن (ناوی بەکارهێنەر « ⁦it_stage_2⁩ » بە بۆشاییەوە)
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() لابران. ناوی وێنەکە هەڕەمەکییە، بۆیە هی تۆ جیاواز دەبێت.

Email contains only spaces, no picture chosenئیمەیڵ تەنها بۆشایی تێدایە، هیچ وێنەیەک هەڵنەبژێردراوە
HTML sent to the browserئەو HTMLـەی دەنێردرێت بۆ تۆڕگەڕ
<p>Please fill out all inputs.</p>
Everything filled in, but nothing valid (a text file renamed to .png)هەموو شتێک پڕکراوەتەوە، بەڵام هیچیان دروست نین (فایلێکی دەقی کە ناوی گۆڕدراوە بۆ ⁦.png⁩)
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>
Profile.php opened directly in the browser⁦Profile.php⁩ ڕاستەوخۆ لە تۆڕگەڕدا کرایەوە
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 و نەگۆڕەکان

Item 1دانەی 1challenge-1.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$result = print(null);
echo $result;
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 2دانەی 2challenge-2.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$result = print("hey");
print $result;
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 3دانەی 3challenge-3.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$result = print(null);
print $result;
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 4دانەی 4challenge-4.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
define("w4", 3.14);
echo "w4";
Quick checkپشکنینی خێراWhat is the output? چییە؟

The output challenge: 20 questionsتەحەدای دەرخستە: ⁦20⁩ پرسیار

Round 2: switchقۆناغی ⁦2: switch⁩

Item 5دانەی 5challenge-5.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 5;
switch ($x) {
    case 1:
        echo "1";
    case 5:
        continue;
        echo "5";
    case 6:
        echo "6";
}
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 6دانەی 6challenge-6.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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;
Quick checkپشکنینی خێراWhat is the output? چییە؟

The output challenge: 20 questionsتەحەدای دەرخستە: ⁦20⁩ پرسیار

Round 3: loopsقۆناغی 3: خولەکان

Item 7دانەی 7challenge-7.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 10;
do {
    echo $x;
    $x++;
} while ($x <= 5);

echo "<br />" . $x;
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 8دانەی 8challenge-8.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
while (true)
    if (true)
        break;
Quick checkپشکنینی خێراWhat is the output? چییە؟

The output challenge: 20 questionsتەحەدای دەرخستە: ⁦20⁩ پرسیار

Round 4: functionsقۆناغی 4: کردارەکان

Item 9دانەی 9challenge-9.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
function x() {
    return "Hey";
    echo "How";
}

echo x();
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 10دانەی ⁦10⁩challenge-10.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
function addFive($num) {
    return $num += 5;
}

echo addfivE(5);
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 11دانەی ⁦11⁩challenge-11.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
function addFive($num) {
    return $num += 5;
}

function addSix(&$num) {
    return $num += 6;
}

echo addsix(5);
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 12دانەی ⁦12⁩challenge-12.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
function addFive($num) {
    return $num += 5;
}

function addSix(&$num) {
    return $num += 6;
}

echo addsix(ADDFive(5));
Quick checkپشکنینی خێراWhat is the output? چییە؟

The output challenge: 20 questionsتەحەدای دەرخستە: ⁦20⁩ پرسیار

Round 5: function names and scopeقۆناغی 5: ناوی کردارەکان و مەودا

Item 13دانەی ⁦13⁩challenge-13.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
function a() {}
function A() {}

echo "Done";
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 14دانەی ⁦14⁩challenge-14.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 5;
test();

function test() {
    global $x = 7;
    echo $x;
}

echo $x;
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 15دانەی ⁦15⁩challenge-15.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$x = 5;
test();

function test() {
    global $x, $y;
    echo $x;
}

echo $x;
Quick checkپشکنینی خێراWhat is the output? چییە؟

The output challenge: 20 questionsتەحەدای دەرخستە: ⁦20⁩ پرسیار

Round 6: arraysقۆناغی 6: ڕیزەکەکان

Item 16دانەی ⁦16⁩challenge-16.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$a = []; // the same as: $a = array();
echo $a;
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 17دانەی ⁦17⁩challenge-17.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$a = []; // the same as: $a = array();
$a[0] = "Aram";
$a[1] = "Shilan";
echo $a[1];
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 18دانەی ⁦18⁩challenge-18.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
// $a = [];   <- this line is commented out
$a[0] = "Aram";
$a[1] = "Shilan";
echo $a[0];
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 19دانەی ⁦19⁩challenge-19.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$a['A'] = "Aram";
$a[1] = "Shilan";
echo "$a[A]";
echo "<br />";
echo "$a[1]";
Quick checkپشکنینی خێراWhat is the output? چییە؟

Item 20دانەی ⁦20⁩challenge-20.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
$mixed = array(8 => "Karwan", 'TR' => 'Shilan', 'Aram', 'Dilan');
echo $mixed[10];
echo $mixed[8];
echo $mixed[9];
echo $mixed['TR'];
Quick checkپشکنینی خێراWhat is the output? چییە؟

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) هەڵگیرابوون، نەک پرسیارەکان. بە ڕێکخراوی، داوای ئەمانەیان کردبوو:

  1. Ten complex and challenging output questions for an exam paper that mix multidimensional arrays with normal functions, the global keyword and functions such as strlen(), count() and strpos().
  2. Five complex and challenging output questions that use only for, while and do ... while loops.
  1. دە پرسیاری ئاڵۆز و قورسی بۆ پەڕەی تاقیکردنەوە کە لەگەڵ ئاسایی، وشەی کلیلیی global و وەک strlen()، count() و strpos() تێکەڵ بکەن.
  2. پێنج پرسیاری ئاڵۆز و قورسی کە تەنها 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⁩، کام بابەتەکان، چەند پرسیار و «سەرەتا پرسیار، دواتر چارەسەر».
A better promptpromptـێکی باشترTEXT
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 I Would Use AI to Learn Coding Faster (5 Steps That Actually Work)Developete · Englishئینگلیزی · 126K viewsبینین · 4.9K likesلایک

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⁩ دووەم (تەنها ).

ExerciseڕاهێنانPractice question 1پرسیاری ڕاهێنان 1

Arrays, global, count() and strlen(): what is printed?

، global، count() و strlen(): چی چاپ دەکرێت؟

ai-q1.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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وەڵامەکە پیشان بدە
Output (PHP 8.5)دەرخستە ⁦(PHP 8.5)⁩
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 چاپ دەکرێت.

ExerciseڕاهێنانPractice question 2پرسیاری ڕاهێنان 2

A 2-D array and strpos(): what is printed?

و strpos(): چی چاپ دەکرێت؟

ai-q2.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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وەڵامەکە پیشان بدە
Output (PHP 8.5)دەرخستە ⁦(PHP 8.5)⁩
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 وەک «نەدۆزرایەوە» دەردەکەوێت.

ExerciseڕاهێنانPractice question 3پرسیاری ڕاهێنان 3

Nested arrays and count(..., COUNT_RECURSIVE): what is printed?

ناوەکی و count(..., COUNT_RECURSIVE): چی چاپ دەکرێت؟

ai-q3.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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وەڵامەکە پیشان بدە
Output (PHP 8.5)دەرخستە ⁦(PHP 8.5)⁩
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.

ExerciseڕاهێنانPractice question 4پرسیاری ڕاهێنان 4

for with a step of 3, and while counting down: what is printed?

for بە هەنگاوی 3 و while کە بەرەو خوار دەژمێرێت: چی چاپ دەکرێت؟

ai-q4.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?php
for ($i = 1; $i <= 10; $i += 3) {
    echo $i;
}
echo "|";

$j = 5;
while ($j > 0) {
    $j -= 2;
    echo $j;
}
Show answerوەڵامەکە پیشان بدە
Output (PHP 8.5)دەرخستە ⁦(PHP 8.5)⁩
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⁩ هەڵەیە.

ExerciseڕاهێنانPractice question 5پرسیاری ڕاهێنان 5

continue inside do ... while, and a for loop with two variables: what is printed?

continue لە ناو do ... whileـدا و بە دوو : چی چاپ دەکرێت؟

ai-q5.phpPHPRuns on the serverلەسەر ڕاژەکاری وێب کار دەکات
<?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وەڵامەکە پیشان بدە
Output (PHP 8.5)دەرخستە ⁦(PHP 8.5)⁩
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هەنگاوەکانی دوای ئەم کۆرسە

Learn Object Oriented PHP for Beginners | With Examples to Help You Understand! | OOP PHP TutorialDani Krossing · Englishئینگلیزی · 157K viewsبینین · 3.9K likesلایک · Partبەشی 0:00–26:28 (ofلە 58:16)

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:

پێش تاقیکردنەوە، دڵنیابە کە دەتوانیت هەر یەکێک لەمانە بەبێ تێبینی بکەیت:

  1. Explain internet vs Web, client vs server, URL parts, DNS and the HTTP request/response cycle.
  2. Start XAMPP and run a page from htdocs.
  3. Write variables, strings, operators, if/switch and the four loops, and predict their output.
  4. Write functions with parameters, defaults and references; use indexed, associative and multidimensional arrays and sort them.
  5. Build a form, read it with $_GET/$_POST, validate it, escape the output, and handle a file upload.
  6. Create a table, then INSERT, SELECT, UPDATE and DELETE from PHP with prepared statements.
  7. Use cookies and sessions, and build register / login / logout with password_hash() and password_verify().
  8. Explain what an API is, and turn PHP arrays into JSON and back.
  1. جیاوازیی و ، و ، بەشەکانی ، و سووڕی / HTTP ڕوون بکەیتەوە.
  2. دەست پێبکەیت و پەڕەیەک لە htdocsـەوە جێبەجێ بکەیت.
  3. ، ، ، if/switch و چوار بنووسیت و پێشبینی بکەیت.
  4. بە ، و بنووسیت؛ ، و بەکاربهێنیت و ڕیزیان بکەیت.
  5. دروست بکەیت، بە $_GET/$_POST بیخوێنیتەوە، بکەیت، پارێزراو بکەیت و بەڕێوە ببەیت.
  6. دروست بکەیت، پاشان بە لە PHPـەوە INSERT، SELECT، UPDATE و DELETE بکەیت.
  7. و بەکاربهێنیت و / / بە password_hash() و password_verify() دروست بکەیت.
  8. ڕوون بکەیتەوە چییە و PHP بکەیت بە JSON و بە پێچەوانەوە.
Review questionsپرسیارەکانی پێداچوونەوە
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.ڤیدیۆیەک کە بینەران زۆریان پێ خۆش بووە و لە کۆمێنتەکانیاندا ستایشیان کردووە، بۆ ئەم وانەیە هەڵبژێردراوە.

PHP Full Course for free 🐘Bro Code · Englishئینگلیزی · 3M viewsبینین · 65K likesلایک · Partبەشی 0:00–3:26:07 (ofلە 4:00:00)

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زاراوە سەرەکییەکان

References and further readingسەرچاوەکان و خوێندنەوەی زیاتر

This lecture is a first edition. The Kurdish text and terminology are waiting for review by Kurdish IT teachers.ئەم وانەیە چاپی یەکەمە. دەقە کوردییەکە و زاراوەکانی چاوەڕێی پێداچوونەوەی مامۆستایانی کوردی بواری IT ن.