Results 1 to 4 of 4

Thread: mysqli_result error

  1. #1
    Join Date
    Jun 2011

    mysqli_result error

    I am fairly new to php. I got the following error message from some code I generated and am not sure what to look for. It came from some sample code I found.
    Catchable fatal error: Object of class mysqli_result could not be converted to string in C:\xampp\htdocs\petDisplaytest1.php on line 24

    Could it be a key error. My database has text and numbers in it . Any help would be appreciated

  2. #2
    Join Date
    Aug 2004
    Tough to be sure without seeing the actual code. It could be some sort of query syntax error that isn't be caught via some reasonable defensive coding before trying to use the result of that query.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Feb 2011
    Check if you forgot to add the ' > ' in the sintax $object->method()

  4. #4
    Join Date
    Jun 2011
    Here is the code.
    /* Program: petDisplay.php
    * Desc: Displays all pets in selected category.
    <head><title>Pet Catalog</title></head>
    $database = "PetCatalog";
    $cxn = mysqli_connect($host,$user,$password,$database)
    or die ("couldn't connect to server");
    $pettype = "cat"; //horse was typed in a form by user
    $query = "SELECT * FROM Pet WHERE petType='$pettype'";
    $result = mysqli_query($cxn,$query)
    or die ("Couldn't execute query.");

    /* Display results in a table */
    $pettype = ucfirst($pettype)."s";
    echo "<h1>$pettype</h1>\n";
    echo "<h1>$result</h1>\n";
    echo "<table cellspacing='15'>\n";
    echo "<tr><td colspan='3'><hr /></td></tr>\n";
    while($row = mysqli_fetch_assoc($result))
    $f_price = number_format($price,2);
    echo "<tr>\n
    <td style='text-align: right'>\$$f_price</td>\n
    echo "<tr><td colspan='3'><hr /></td></tr>\n";
    echo "</table>\n";
    It is sample code from a php testbook that shall remain nameless. I removed user and password
    I added a couple of echo statements to help me test.
    I have also listed the table structure below
    PetId int(11) No None
    Petname varchar(25) latin1_swedish_ci No None
    Pettype varchar(25) latin1_swedish_ci No None
    PetDescription varchar(255) latin1_swedish_ci No None
    Price decimal(9,2) No None
    pix varchar(15) latin1_swedish_ci No None

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center