Can someone tell me what this error message means?

Discussion in 'PHP' started by Mitchell, Jun 21, 2010.

  1. #1
    Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\htdocs\clphp03\new_post09.php on line 112

    Line 112 $
    result = $db->query($sql) or die(mysqli_error());

    
    $db = dbConnect('query');
        $sql = 'SELECT * FROM mammals WHERE postid = $postid';
        $result = $db->query($sql) or die(mysqli_error());
        while ($row = $result->fetch_assoc()) {
            echo $row['postid'];
            }
    
    PHP:

     
    Mitchell, Jun 21, 2010 IP
  2. ttyler333

    ttyler333 Member

    Messages:
    62
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    43
    #2
    i think it is this part of your code $sql = 'SELECT * FROM mammals WHERE postid = $postid';

    it should possibly be $sql = "SELECT * FROM mammals WHERE postid = '$postid'";
     
    ttyler333, Jun 21, 2010 IP
  3. Mitchell

    Mitchell Peon

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks for the help.

    I did what you suggested, but I get the same error message. Perhaps your suggestion corrected part of the problem.
     
    Mitchell, Jun 21, 2010 IP
  4. Mitchell

    Mitchell Peon

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I removed or die(mysqli_error()) and I get a new error message.

    Fatal error: Call to a member function fetch_assoc() on a non-object in C:\htdocs\clphp03\new_post09.php on line 113
     
    Mitchell, Jun 21, 2010 IP
  5. bogdanas

    bogdanas Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Shouldn't line:
    $db = dbConnect('query');
    be:
    $db = new dbConnect('query');
     
    bogdanas, Jun 21, 2010 IP
  6. Mitchell

    Mitchell Peon

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks for the help. When I add new I get a different error message.

    Fatal error: Class 'dbConnect' not found in C:\htdocs\clphp03\new_post09.php on line 110
     
    Mitchell, Jun 21, 2010 IP
  7. bogdanas

    bogdanas Peon

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    show full source
     
    bogdanas, Jun 21, 2010 IP
  8. bvraghav

    bvraghav Member

    Messages:
    123
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    33
    #8
    well, the answer is in your post itself. Click on mysqli_error in your code.

    The function accepts a "resource link" argument.. that is giving you the error...
    $result = $db->query($sql) or die( mysqli_error( $result ) );
    PHP:
    alternately, if your $db is a mysqli object ( or inherits mysqli ), you can use
    $result = $db->query($sql) or die( $db->error );
    PHP:
    hopefully this solves... :)
     
    bvraghav, Jun 22, 2010 IP
  9. Mitchell

    Mitchell Peon

    Messages:
    204
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Thank you all for your help.

    bvraghav was right on.

    I tried or die( mysqli_error( $result ) ); and got nothing. Then I tried or die( $db->error ); and received an error message telling me there was no such table with that name. I forgot to update the name of the table in that last piece of code.
     
    Mitchell, Jun 22, 2010 IP