Manual
Manual
1. PHP Arrays
PHP arrays are data structures that allow you to store multiple values in a single variable.
There are three types of arrays in PHP: indexed, associative, and multidimensional arrays.
Indexed arrays use numeric keys, while associative arrays use named keys.
PHP can be embedded in an HTML page using PHP tags (<?php ?>) inside an HTML
document.
Example:
<!DOCTYPE html>
<html>
<head>
<title>PHP Example</title>
</head>
<body>
<h1>Welcome to My Page</h1>
<?php
$message = "Hello, World!";
echo "<p>$message</p>";
?>
</body>
</html>
1. Sessions store data on the server and are identified by a unique session ID.
Example of session for user authentication:
session_start();
$_SESSION['user'] = 'JohnDoe'; // Store user data
echo "Welcome, " . $_SESSION['user']; // Access user data
GET vs POST
- GET sends data via URL parameters, making it less secure.
- POST sends data in the request body, suitable for sensitive information.
Create Operation
$sql = "INSERT INTO users (name, email) VALUES ('John', '[email protected]')";
$conn->query($sql);
Read Operation
$sql = "SELECT * FROM users";
$result = $conn->query($sql);
Update Operation
$sql = "UPDATE users SET email = '[email protected]' WHERE id = 1";
$conn->query($sql);
Delete Operation
$sql = "DELETE FROM users WHERE id = 1";
$conn->query($sql);