Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2004

    Unanswered: Why does this code give a "property of non-object"message?


    I am working through a Learn PHP/MSQL book to attempt to learn more about PHP/MYSQL and am trying to make an example piece of code to run from the book, but I keep getting this error message
    Notice: Trying to get property of non-object in C:\xampp\htdocs\testsite\using_insert_ids.php on line 8
    The code in the book is as follows -
    PHP Code:
    require_once 'login.php';  
    $conn = new mysqli($hn$un$pw$db);  
    if (
    $conn->connect_error) die($conn->connect_error);

    $query  "INSERT INTO cats VALUES(NULL, 'Lynx', 'Stumpy', 5)";  
    $result $conn->query($query);  
    $insertID $result->insert_id;
    $query    "INSERT INTO owners VALUES($insertID, 'Ann', 'Smith')"
    $result   $conn->query($query);
    The code does insert the values into the 'cats' table, but php outputs the non-object message above into the browser.

    Any help would be appreciated! Thank you.


  2. #2
    Join Date
    Aug 2004
    I have resolved this.

    The problem was the line
    PHP Code:
    $insertID $result->insert_id
    should have used $conn instead of $result.

Posting Permissions

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