0

I have This php Function for get data for dynamic select box. i get country using form post method and put in dropdown menu. This function retrieve data from mysql :

   function drop_1($drop_var)
{  
    include_once('db.php');
    $result = mysql_query("SELECT * FROM home WHERE date='$drop_var' ") 
    or die(mysql_error());

    echo '<select name="drop_2" id="drop_2">
          <option value=" " disabled="disabled" selected="selected">Choose one</option>';

           while($drop_2 = mysql_fetch_array( $result )) 
            {
              echo '<option value="'.$drop_2['date'].'">'.$drop_2['data'].'</option>';
            }
 }  

Now when i retireve data using jquery. I See this Error :

fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\test\func.php on line 14

This Line 14 : **$result = $db->query ($mysql);**

What's Problem ? Thanks

5
  • Where is $db defined? There error states that you try to acces query in the object $db. But that $db is not an object. So how do you define $db? Commented Mar 15, 2012 at 8:31
  • When you want to create object , first you need class for that , where is your class ? Commented Mar 15, 2012 at 8:37
  • Can you give us the line where you typ: $db = ...... Commented Mar 15, 2012 at 8:47
  • @SynerCoder : i dont care ! whats your mean : $db = ........ Commented Mar 15, 2012 at 8:52
  • The whole point of your error is about how your defined $db. Is $db a object or not? Aka: is $db defined as followed: $db = new MyClass(); or $db = "string"; or $db = 12;. We need that line to discover your problem. Commented Mar 15, 2012 at 8:56

1 Answer 1

1

$db belong to which class ? is there any class for $db object ? make that class OR include from some where...

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

3 Comments

I Edited and Add $db function to my question
$db = new DB... something like this OR directly use like $result = query($mysql);
whitout db function this worked : include_once('db.php'); $result = mysql_query("SELECT * FROM data WHERE home='$drop_var'") or die(mysql_error()); while($drop_3 = mysql_fetch_array( $result ))

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.