https://github.com/pernillasterner/php_fundamentals
PHP For Beginners
https://github.com/pernillasterner/php_fundamentals
controllers form-validation mysql partials pdo-mysql php routing sql tailwindcss views
Last synced: 10 months ago
JSON representation
PHP For Beginners
- Host: GitHub
- URL: https://github.com/pernillasterner/php_fundamentals
- Owner: pernillasterner
- Created: 2024-11-11T14:54:42.000Z (over 1 year ago)
- Default Branch: development
- Last Pushed: 2025-06-09T08:49:50.000Z (11 months ago)
- Last Synced: 2025-06-09T09:35:52.694Z (11 months ago)
- Topics: controllers, form-validation, mysql, partials, pdo-mysql, php, routing, sql, tailwindcss, views
- Language: PHP
- Homepage:
- Size: 71.3 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHP for Beginners
A basic project demonstrating how to build a simple PHP application with partials, views, controllers, and a basic router. TailwindCSS is also used to quickly implement modern and responsive styling.
### Separating URI and Query in PHP
To separate the URI path and query parameters in PHP, you can use the `parse_url` function.
```php
$uri = "/contact?name=johndoe";
print_r(parse_url($uri));
// Output
array(2) {
["path"] =>
string(8) "/contact"
["query"] =>
string(12) "name=johndoe"
}
```
### Securely Querying a Database with Placeholders
Using placeholders in SQL queries is important for security reasons. It helps to protect the db from SQL injection attacks.
```php
// Retrieving the 'id' parameter from the URL (?id=2)
$id = $_GET['id'];
// Creating the query with a placeholder
$query = "select * from posts where id = :id";
// Executing the query and binding the placeholder with the actual value of $id.
$posts = $db->query($query, [':id' => $id])->fetch();
// Output the data
dd($posts);
```