Load PHP page via database ID

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Load PHP page via database ID

Post by Celauran »

Looks like you're stuck using MySQLi, then. Unfortunate, but not the end of the world. The code in my previous example would become:

Code: Select all

<?php

$sql = new mysqli('localhost', 'username', 'password', 'database_name');

if (isset($_GET['id'])) {
    $query = "SELECT name, username, content FROM pages WHERE id = ?";
    $stmt = $sql->prepare($query);
    $stmt->bind_param('i', $_GET['id']);
    $stmt->execute();
    $stmt->bind_result($name, $username, $content);
    $stmt->fetch();
}
Post Reply