4D.
4D.

Reputation: 11

PHP Notice: Undefined property: stdClass:

I've got an array coming back from a Flash app created in Flash Builder 4.

I have a service setup that queries and brings data back from the DB successfully, however the Update script is generating the Undefined Property errors.

I'm still learning both PHP and Flash Builder, and don't fully understand what the $this-> commands do.

If anyone can suggest where this script is going wrong, it is basically just generated by Flash Builder and is not something I've developed myself, I would appreciate it?

Also if someone can explain $this-> to me that would be awesome too?

I've seen them before, but then I've seen scripts doing the same thing that do not use them, so is this an old way of doing things?

Really appreciate any input anyone can give.

Updated for full PHP code.

Errors Generated.

[18-Jun-2010 13:01:37] PHP Notice: Undefined property: stdClass::$inst_code in C:\wamp\www\Coradia-175105-debug\services\tbltrustservice.php on line 48

[18-Jun-2010 13:01:37] PHP Notice: Undefined property: stdClass::$trust_name in C:\wamp\www\Coradia-175105-debug\services\tbltrustservice.php on line 48

[18-Jun-2010 13:01:38] PHP Notice: Undefined property: stdClass::$trust_code in C:\wamp\www\Coradia-175105-debug\services\tbltrustservice.php on line 48

[18-Jun-2010 13:01:38] PHP Notice: Undefined property: stdClass::$trust_key in C:\wamp\www\Coradia-175105-debug\services\tbltrustservice.php on line 48

        <?php

//reroute errors to get rid of that annoying CHANNEL DISCONNECTED message.
ini_set('error_log', 'errorLog.txt');
ini_set('html_errors', '0');
ini_set('display_errors', '0');
ini_set('log_errors', '1');

class tbltrustservice {

    public $connection;

    public function connect() {
            $this->connection = mysqli_connect("ahoey-1:3306",  "<Username Removed For StackOverflow>",  "<Password Removed for StackOverflow>", "enabmodules") or die(mysqli_connect_error());
    }

    public function getAllItems($search) {
              $this->connect();

              if ($search=="") {
              $sql = "SELECT * FROM tbltrust";
              } else {
              $sql = 'SELECT * FROM tbltrust WHERE trust_name LIKE \'%'.mysql_escape_string($search).'%\' OR trust_code LIKE \''.mysql_escape_string($search).'%\' OR inst_code LIKE \'%'.mysql_escape_string($search).'%\'';
              }

              $result = mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));

              $rows = array();
              while ($row = mysqli_fetch_object($result)) {
                    $rows[] = $row;
              }

              mysqli_free_result($result);
              mysqli_close($this->connection);

              return $rows; 
    }



    public function updateItem($item) {
        // TODO Auto-generated method stub
        // Update an existing record in the database and return the item

        // Sample code \'

              $this->connect();
              $sql = "UPDATE tbltrust SET inst_code = '$item->inst_code', trust_name = '$item->trust_name', trust_code = '$item->trust_code' WHERE  trust_key = '$item->trust_key'";

              mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));

              mysqli_close($this->connection);

    }


/*
    public function updateItem($item) {

        $stmt = mysqli_prepare($this->connection, "UPDATE $this->tablename SET trust_code=?, trust_name=?, inst_code=? WHERE trust_key=?");     
        $this->throwExceptionOnError();

        mysqli_stmt_bind_param($stmt, 'sssi', $item->trust_code, $item->trust_name, $item->inst_code, $item->trust_key);        
        $this->throwExceptionOnError();

        mysqli_stmt_execute($stmt);     
        $this->throwExceptionOnError();

        mysqli_stmt_free_result($stmt);     
        mysqli_close($this->connection);
    }
*/
    public function getItem($itemID) {
        // TODO Auto-generated method stub
        // Return a single record from the database and return the item

        // Sample code
        /*
              $this->connect();
              $itemID = mysqli_real_escape_string($this->connection, $itemID);
              $sql = "SELECT * FROM books where itemID=$itemID";

              $result = mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));

              $rows = array();
              while ($row = mysqli_fetch_object($result)) {
                    $rows[] = $row;
              }

              mysqli_free_result($result);
              mysqli_close($this->connection);

              return $rows;
        */  
    }

    public function createItem($item) {
        // TODO Auto-generated method stub
        // Insert a new record in the database using the parameter and return the item

        // Sample code
        /*
              $this->connect();
              $sql = "INSERT INTO books (title, au_first_name, au_last_name) 
              VALUES ('$item->title','$item->au_first_name','$item->au_last_name')";  

              mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));

              $autoid= mysqli_insert_id($this->connection);
              mysqli_close($this->connection);

              return $autoid;
        */  
    }

/*
public function updateItem($item) {

        $stmt = mysqli_prepare($this->connection, "UPDATE tbltrust SET trust_code=?, trust_name=?, inst_code=? WHERE trust_key=?");     
        $this->throwExceptionOnError();

        mysqli_stmt_bind_param($stmt, 'sssi', $item->trust_code, $item->trust_name, $item->inst_code, $item->trust_key);        
        $this->throwExceptionOnError();

        mysqli_stmt_execute($stmt);     
        $this->throwExceptionOnError();

        mysqli_stmt_free_result($stmt);     
        mysqli_close($this->connection);
    } */

    public function deleteItem($itemID) {
        // TODO Auto-generated method stub
        // Delete a record in the database

        // Sample code
        /*
              $this->connect();
              $itemID = mysqli_real_escape_string($this->connection, $itemID); 
              $sql = "DELETE FROM books WHERE itemID = $itemID";

              mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));

              mysqli_close($this->connection);
        */  
    }

    public function count() {
        // TODO Auto-generated method stub
        // Return the number of items in your array of records

        // Sample code
        /*
              $this->connect();
              $sql = "SELECT * FROM books";

              $result = mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));
              $rec_count = mysqli_num_rows($result);

              mysqli_free_result($result);
              mysqli_close($this->connection);

              return $rec_count;
        */  
    }

    public function getItems_paged($startIndex, $numItems) {
        // TODO Auto-generated method stub
        // Return a page of records as an array from the database for this startIndex

        // Sample code
        /*
              $this->connect();
              $startIndex = mysqli_real_escape_string($this->connection, $startIndex); 
              $numItems = mysqli_real_escape_string($this->connection, $numItems); 
              $sql = "SELECT * FROM books LIMIT $startIndex, $numItems";

              $result = mysqli_query($this->connection, $sql) or die('Query failed: ' . mysqli_error($this->connection));

              $rows = array();
              while ($row = mysqli_fetch_object($result)) {
                    $rows[] = $row;
              }

              mysqli_free_result($result);
              mysqli_close($this->connection);

              return $rows;
        */  
    }


    }

?>

Upvotes: 0

Views: 8510

Answers (1)

Palantir
Palantir

Reputation: 24182

Oh my :)

$this is the "name" of the current object you are in. I believe that you have just copied that function from inside a larger object, pasted it in a random place, and it now stopped working, because it is missing essential parts of itself...

To use that script, you need the full source code. You should better try to learn some PHP basics, otherwise you will have a hard time figuring them out by yourself.

Upvotes: 3

Related Questions