SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Wizard billy_111's Avatar
    Join Date
    Jul 2009
    Posts
    1,683
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why wont this work: Trying to get property of non-object

    Hi,

    I really don't understand why this does not work..

    PHP Code:
            $prod_model = new Product();
            
    $products $prod_model->selectByID(1);
            
    $items mysql_fetch_object($products);
            echo 
    $items->name//I get error here 
    This line:

    PHP Code:
    $prod_model = new Product(); 
    Just refers to this class:

    PHP Code:

    class Product{

        public function 
    selectByID($ID){

            
    $query "SELECT * FROM tbl_item WHERE deleted = 0 AND ID = ".$ID;
            return 
    mysql_query($query) or die(mysql_error());
        }

    The specific record exists in the database, i have even tried using :

    PHP Code:
     $items mysql_fetch_array($products); 
    Only difference here is that it shows nothing at all..

    Can anyone please help me..

    Thanks again
    Software Engineer ASP, ASP.NET, VB, PHP

    Kind regards
    Billy

  2. #2
    SitePoint Addict
    Join Date
    Oct 2003
    Location
    United States
    Posts
    281
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have you tried running your query in the database?

    if you echo $query; and copy that code into PhpMyadmin, does it give you an error? Your php code looks fine to me. I'm assuming you already opened up a database connection earlier in the script.

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    - First check the record deleted = 0
    - Second do you have a field named 'name' in the table?
    - Try to echo the query and run it outside PHP (mysql client or phpmyadmin) whether it gives you the record.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5


Bookmarks

Posting Permissions

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