Skip to content

rniguel/php-course-brocode

Repository files navigation

PHP Full Course Exercises - Bro Code

Exercises from the PHP Full Course by Bro Code - a complete beginner's guide to PHP covering everything from variables to database integration.

Author: MiguelGitHub


Topics Covered

# Category Description Exercises
01 Basics Variables, types, arithmetic, math functions 5
02 Control Structures if/else, switch, for, while loops 6
03 Strings String manipulation functions 1
04 Arrays Indexed and associative arrays 2
05 Functions Custom functions, arguments, return values 1
06 Forms GET, POST, radio buttons, checkboxes 6
07 Security Validation, sanitization, hashing, $_SERVER 3
08 Sessions & Cookies Session management, cookies 3
09 Includes Code organization with include() 1
10 Database MySQL connection, CRUD, login system 3

Project Structure

php-course-brocode/
├── index.php                          # Main navigation page
├── README.md
├── 01-basics/
│   ├── variables.php                  # Variables & data types
│   ├── arithmetic.php                 # Arithmetic operators
│   ├── operator-precedence.php        # Operator precedence
│   ├── increment-decrement.php        # Increment & decrement
│   └── math-functions.php             # Built-in math functions
├── 02-control-structures/
│   ├── if-else.php                    # If/else conditionals
│   ├── if-elseif.php                  # If/elseif (pay calculator)
│   ├── logical-operators.php          # &&, ||, ! operators
│   ├── switch.php                     # Switch statement
│   ├── for-loops.php                  # For loops
│   └── while.php                      # While loops
├── 03-strings/
│   └── string-functions.php           # String manipulation
├── 04-arrays/
│   ├── arrays.php                     # Indexed arrays
│   └── associative-arrays.php         # Associative arrays
├── 05-functions/
│   └── functions.php                  # Custom functions
├── 06-forms/
│   ├── login.php                      # Login form (POST)
│   ├── calculate-pizzas.php           # Pizza order (GET)
│   ├── calculate-pi.php               # Circle calculator
│   ├── radio-button.php               # Radio buttons
│   ├── checkbox.php                   # Checkboxes
│   └── isset-empty.php                # isset() & empty()
├── 07-security/
│   ├── validate-form.php              # Form validation
│   ├── server.php                     # $_SERVER superglobal
│   └── hash.php                       # Password hashing
├── 08-sessions-cookies/
│   ├── cookies.php                    # Cookies
│   ├── session-login.php              # Session login
│   └── session-home.php               # Session home (logged in)
├── 09-includes/
│   ├── index.php                      # Include example
│   └── header.html                    # Included header file
└── 10-database/
    ├── database-connect.php           # Database connection
    ├── database-crud.php              # CRUD operations
    └── fakebook.php                   # Registration system

Setup Guide

Prerequisites

  • OS: WSL (Ubuntu) or any Linux distribution
  • Packages: Apache2, PHP, MySQL

1. Update System

sudo apt update && sudo apt upgrade -y

2. Install Apache + PHP + MySQL

sudo apt install apache2 php libapache2-mod-php mysql-server -y

3. Start Services

sudo service apache2 start
sudo service mysql start

4. Set Up Project Directory

Create your project folder and link it to Apache:

mkdir -p ~/www/php
sudo ln -s ~/www/php /var/www/html/php

5. Clone the Repository

cd ~/www/php
git clone git@github.com:rniguel/php-course-brocode.git

6. Find Your IP

hostname -I

7. Access the Project

Open in your browser:

http://YOUR_IP/php/php-course-brocode/

MySQL Setup (for Database Exercises)

Configure Root Password

sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'SenhaForte123!';
FLUSH PRIVILEGES;
EXIT;

Install phpMyAdmin

sudo apt install phpmyadmin -y

During installation:

  • Select Apache2
  • Choose Yes to configure database
  • If password error appears, skip it

Link phpMyAdmin

ln -s /usr/share/phpmyadmin ~/www/php/phpmyadmin

Access at: http://YOUR_IP/php/phpmyadmin

  • User: root
  • Password: (the one you set above)

Create Database for Exercises

Open phpMyAdmin or MySQL CLI and run:

CREATE DATABASE businessdb;
USE businessdb;

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    user VARCHAR(50) NOT NULL,
    password VARCHAR(255) NOT NULL
);

Update the password in 10-database/database-connect.php if yours differs.


Useful Commands

sudo service apache2 start      # Start Apache
sudo service apache2 restart    # Restart Apache
sudo service apache2 status     # Check Apache status
sudo service mysql start        # Start MySQL
sudo service mysql restart      # Restart MySQL
sudo service mysql status       # Check MySQL status

Troubleshooting

localhost doesn't open

  • Make sure Apache is running: sudo service apache2 start

404 Not Found

  • Verify the symlink is correct: ls -la /var/www/html/php
  • Make sure files exist in ~/www/php/

403 Forbidden

  • Fix permissions: chmod -R 755 ~/www/php

phpMyAdmin won't open

  • Create the symlink: ln -s /usr/share/phpmyadmin ~/www/php/phpmyadmin
  • Fix permissions: chmod -R 755 /usr/share/phpmyadmin

MySQL ERROR 1819 (password policy)

  • Use a stronger password with uppercase, lowercase, numbers, and special characters

Can't login to phpMyAdmin

  • Use root as the username
  • Or create a dedicated user:
CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY 'SenhaForte123!';
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;

Apache running but can't access

  • Use your WSL IP (not localhost): http://YOUR_IP/

Git SSH error (publickey)

ssh-keygen -t ed25519 -C "your-email@example.com"

Add the public key to your GitHub account under Settings > SSH keys.


Tech Stack

Technology Purpose
PHP Server-side scripting
Apache Web server
MySQL Database
phpMyAdmin Database management UI
WSL (Ubuntu) Linux environment on Windows

What You'll Learn

  • PHP Syntax: Embedding PHP in HTML, variables, data types
  • Operators: Arithmetic, logical, comparison, assignment
  • Control Flow: if/else, switch, for loops, while loops
  • Data Structures: Indexed arrays, associative arrays, array functions
  • Functions: Custom functions, parameters, return values
  • Forms: Handling GET/POST data, radio buttons, checkboxes
  • Security: Input validation, sanitization, password hashing
  • State Management: Sessions and cookies
  • Code Organization: include() for reusable components
  • Database: MySQL connection, CRUD operations, user registration

References


License

This project is for educational purposes. Feel free to use it as a reference for learning PHP.


Built by MiguelGitHub

About

Exercises from the PHP Full Course by Bro Code - a complete beginner's guide to PHP covering everything from variables to database integration.

Topics

Resources

Stars

Watchers

Forks

Contributors