www.webdeveloper.com
Results 1 to 4 of 4

Thread: mysqli_result error

  1. #1
    Join Date
    Jun 2011
    Posts
    9

    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
    Location
    Ankh-Morpork
    Posts
    19,175
    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.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

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

  4. #4
    Join Date
    Jun 2011
    Posts
    9
    Here is the code.
    <?php
    /* Program: petDisplay.php
    * Desc: Displays all pets in selected category.
    */
    ?>
    <html>
    <head><title>Pet Catalog</title></head>
    <body>
    <?php
    $user="";
    $host="localhost";
    $password="";
    $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))
    {
    extract($row);
    $f_price = number_format($price,2);
    echo "<tr>\n
    <td>$petName</td>\n
    <td>$petDescription</td>\n
    <td style='text-align: right'>\$$f_price</td>\n
    </tr>\n";
    echo "<tr><td colspan='3'><hr /></td></tr>\n";
    }
    echo "</table>\n";
    ?>
    </body></html>
    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



Recent Articles