PHP with MySQL Essential Training: 1 The Basics
Kevin Skoglund
Start a Database-Driven Project
Create and style the first page
Standart bir html kodu şöyle olmalı
<!doctype html>
<html lang="tr">
<head>
<title>...</title>
<link rel="stylesheet" media="all" href="">
</head>
<body>
...
</body>
</html>
Include and require file
include ve require fonksiyonları parametre olarak aldıkları dosya içeriği kullanıldığı yere kopyalar. require fonsiyonu ilgili dosyayı bulamazsa çalışma zamanı hatası oluşur ve kodun yürütülmesi durdurulur. Her iki fonksiyonun include_once ve require_once isimli varyantları vardır. Bunlar kod içinde tekrar kullanılsa bile içeriğin sadece bir kere kopyalanmasını sağlarlar.
Make page assets reusable
DEFINE("xxx", "yyy"); // kodda xxx gördüğü yere yyy yazar
DEFINE ifadesi birinci parametre olarak aldığı değeri kod içinde arar ve bulduğu yere ikinci parametre olarak aldığı değeri yazar
dirname( );
dirname fonksiyonu parametre olarak aldığı dosyanın içinde bulunduğu klasörün yolunu verir
__FILE__
__FILE__ içinde bulunduğu dosyanın adını verir. include edilmiş dosyalarda fiziksel olarak içinde bulunduğu dosyanın adını verir
Use URL parameters
somepage.php?page=2&category=2
$_GET["page"]
Default values for URL parameters
isset($var)
if ( isset( $_GET["page"] ) ) {
//...
} else {
//...
}
$page = isset($_GET['page']) ? $_GET['page'] : '1';
$page = $_GET['page'] ?? '1';
Encode URL parameters
urlencode() // space -> + query kısmında kullanılır
rawurlencode() // space -> %20 path kısmında kullanılır
Encode for HTML
htmlspecialchars()
Modify headers
header($string)
Page redirection
header("Location: list.php");
Build forms
<form action="login.php" method="post">
<input type="text" name="city" value="" />
<input type="submit" value="Submit" />
</form>
-
Start a Database-Driven Project>Blueprint the application
Establish your work area
Create and style the first page
Include and require files
Make page assets reusable -
Build web pages with PHPLinks and URLs
Use URL parameters
Default values for URL parameters
Encode URL parameters
Encode for HTML -
Headers and RedirectsModify headers
Page redirection
Output buffering -
Build Forms with PHPBuild forms
Use form parameters
Detect form submission
Single-page form processing -
MySQL BasicsMySQL introduction
Create a database
Create a database table
CRUD in MySQL
Populate a MySQL table
Relational database tables -
Use PHP to Access MySQLDatabase APIs in PHP
Connect to MySQL with PHP
Retrieve data
Work with retrieved data
Error handling -
CRUD with PHPFind a single record
Use form data to create records
Use form data to update records
Form options from database data
Delete a record -
Validate Data with PHPCommon data validation types
Validate form values
Display validation errors
Problems with validation logic -
Prevent SQL InjectionUnderstand SQL injection
Sanitize data for SQL
Delimit data values
Prepared statements