1. Client-Server Architecture
Web sites execute operations across two primary environments:
- Client-Side: Static files (HTML, CSS, JS) downloaded by the user's browser for rendering and user interaction.
- Server-Side: Scripts (like PHP) executed on the host server to fetch database details before outputting standard HTML to the client browser.
2. Dynamic PHP Scripting
A/L ICT questions frequently test how to connect a PHP script to a MySQL database to read and save user registration inputs.
Sample PHP Database Connection & Write:
<?php
$conn = mysqli_connect("localhost", "root", "", "itguru_db");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = mysqli_real_escape_string($conn, $_POST["name"]);
$email = mysqli_real_escape_string($conn, $_POST["email"]);
$sql = "INSERT INTO Students (Name, Email) VALUES ('$name', '$email')";
if (mysqli_query($conn, $sql)) {
echo "Registration successful!";
} else {
echo "Error: " . mysqli_error($conn);
}
}
mysqli_close($conn);
?>