-1

So i've made a forum for my site and i run intro a problem and here it is

Fatal error: Call to a member function prepare() on a non-object in /home/a8479867/public_html/pages/forum/index.php on line 3

Here is my code

<?php
//...
$query=$db->prepare('SELECT cat_id, cat_nom, 
forum_forum.forum_id, forum_name, forum_desc, forum_post, forum_topic, auth_view, forum_topic.topic_id,  forum_topic.topic_post, post_id, post_time, post_createur, membre_pseudo, 
membre_id 
FROM forum_categorie
LEFT JOIN forum_forum ON forum_categorie.cat_id = forum_forum.forum_cat_id
LEFT JOIN forum_post ON forum_post.post_id = forum_forum.forum_last_post_id
LEFT JOIN forum_topic ON forum_topic.topic_id = forum_post.topic_id
LEFT JOIN forum_membres ON forum_membres.membre_id = forum_post.post_createur
WHERE auth_view <= :lvl 
ORDER BY cat_ordre, forum_ordre DESC');
$query->bindValue(':lvl',$lvl,PDO::PARAM_INT);
$query->execute();
?>
kero
  • 10,647
  • 5
  • 41
  • 51
  • 1
    Where do you define `$db`? Looking at the error, it seems to not be what you expect it to be – kero Mar 10 '14 at 22:08
  • Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user 'my_user'@'localhost' (using password: YES) in /home/a8479867/public_html/pages/forum/index.php on line 3 Warning: mysqli::prepare() [mysqli.prepare]: Couldn't fetch mysqli in /home/a8479867/public_html/pages/forum/index.php on line 13 Fatal error: Call to a member function bindValue() on a non-object in /home/a8479867/public_html/pages/forum/index.php on line 14 – user3401134 Mar 10 '14 at 22:16

1 Answers1

0

you haven't created the "db" object that you're calling on line 3

for mysqli it is $db = new mysqli('localhost', 'my_user', 'my_password', 'db');

as it seems your using pdo its $db = new PDO('mysql:host=localhost;dbname=testdb;charset=utf8', 'username', 'password');

bountyh
  • 165
  • 9
  • Thanks for this it's fix this error but now i have 3 new error – user3401134 Mar 10 '14 at 22:12
  • Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user 'my_user'@'localhost' (using password: YES) in /home/a8479867/public_html/pages/forum/index.php on line 3 Warning: mysqli::prepare() [mysqli.prepare]: Couldn't fetch mysqli in /home/a8479867/public_html/pages/forum/index.php on line 13 Fatal error: Call to a member function bindValue() on a non-object in /home/a8479867/public_html/pages/forum/index.php on line 14 – user3401134 Mar 10 '14 at 22:18
  • first one points out that your pass / user combo isn't right. second error could be caused because the object wasn't instantiated and therefore its "not an object" – bountyh Mar 10 '14 at 22:27