Template !free! | Php Database Website
if (empty($errors)) { $password_hash = password_hash($password, PASSWORD_DEFAULT);
// Fetch user's items $stmt = $pdo->prepare("SELECT * FROM items WHERE user_id = ? ORDER BY created_at DESC"); $stmt->execute([$_SESSION['user_id']]); $items = $stmt->fetchAll(); ?> <?php include 'includes/header.php'; ?> <h2>Welcome, <?= htmlspecialchars($_SESSION['username']) ?>!</h2> php database website template
<?php // config/database.php $host = 'localhost'; $dbname = 'php_template_db'; $username = 'root'; // Change for production $password = ''; // Change for production try { $pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password); // Set PDO to throw exceptions on errors $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Fetch associative arrays by default $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); } catch(PDOException $e) { die("Database connection failed: " . $e->getMessage()); } $items = $stmt->
form div { margin-bottom: 1rem; }
* { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: Arial, sans-serif; line-height: 1.6; background: #f4f4f4; } ?php include 'includes/header.php'