1

I'm in the process of making a forum, I'm trying to take values from a MySQL and put them in the $f_id, $f_name, $f_desc and $f_date" variables. It's not working for some reason:

<?php
   session_start();
   require"db_connect.php";
   $sql = "SELECT forum_id, forum_name, forum_desc, forum_date FROM forum_tbl";     
      if ($query = $db->prepare($sql)){
      $query->bind_result($f_id, $f_name, $f_desc, $f_date);
      $query->execute();  
   }else{
      echo $db->error;
   }
?>  

And the contents of connect.php:

<?php
     $db = new mysql("DOMAIN","USERNAME","PASSWORD") or die ("ERROR");
?>  
2
  • what are you getting returned for an error? Commented Sep 12, 2013 at 18:42
  • Are any error messages displayed? When you say "It's not working" what do you mean exactly? What indicates that its not working? Commented Sep 12, 2013 at 18:43

2 Answers 2

2

You have a few issues.

  • As answered by Ridz, it's not mysql it's mysqli.
  • You need to call execute() before bind_result()
  • You are not fetching your results.

    if ($query = $db->prepare($sql)){
       $query->execute();  
       $query->bind_result($f_id, $f_name, $f_desc, $f_date);   
    }
    
    // fetch results
    while ($query->fetch()) {
        echo $f_id, $f_name, $f_desc, $f_date;
    }
    

Welcome to StackOverflow.

Sign up to request clarification or add additional context in comments.

Comments

1

bind_result is a mysqli function.

$db = new mysqli("DOMAIN","USERNAME","PASSWORD") or die ("ERROR");

1 Comment

+ this is at least part of the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.