tags:

views:

84

answers:

2

What am I doing wrong here folks?

<?php
include 'header.php';

/**
* Display a user's profile
*/

$id = $db->real_escape_string($_GET['id']);
$user_res = $db->query("SELECT * FROM users WHERE id = $id");
$user = $user_res->fetch_assoc();
?>

<h1><?php echo $user['username'] ?>'s Profile</h1>

<?php
include 'footer.php';
?>

Equals to:
Fatal error: Call to a member function real_escape_string() on a non-object in C:\wamp\www\test\profile.php on line 12</pre>

+1  A: 

You do not have a variable $db, or $db is not the database object you expect. You either need to create it first, or it should have been created in header.php but wasn't.

John Kugelman
A: 

In your line

$db->real_escape_string($_GET['id']);

$db is supposed to be an object, but apparently it is either nothing or something that's no an object. You need to instantiate (create) the object at some point.

$db = new DatabaseObject();
// substitute "DatabaseObject" with the actual name of the Class

Did you do that?

deceze