PHP - Call To A Member Function Call() On A Non-object Question
I can call the following function successfully as a single php program
// Acknowledge and clear the orders function ack($client, $merchant, $id) { $docs = array('string' => $id); $params = array('merchant' => $merchant, 'documentIdentifierArray' => $docs); $result = $client->call('postDocumentDownloadAck', $params); return $result; } with $result = ack($t, $merchant,'2779540483'); successful output [documentDownloadAckProcessingStatus] => _SUCCESSFUL_ [documentID] => 2779540483 I'm trying to figure out how to call this function as an object from another program. Trying the following gives error ***Call to a member function call() on a non-object*** function postDocumentDownloadAck($t, $merchant, $id) { $this->error = null; $docs = array('string' => $this->id); $params = array('merchant' => $this->merchant, 'documentIdentifierArray' => $docs); ** I've tried the following which does nothing $result = $this->soap->call('postDocumentDownloadAck', $params); ** I've tried the following - which gives error "Call to a member function call() on a non-object" $result = $this->t->soap->call('postDocumentDownloadAck', $params); if($this->soap->fault) { $this->error = $result; return false; } return $result; } *** calling program snippet for above function $merchant= array( "merchant"=> $merchantid, "merchantName" => $merchantname, "email"=> $login, "password"=> $password); $t = new AmazonMerchantAPI($merchantid, $merchantname, $login, $password); $documentlist= $t->GetAllPendingDocumentInfo('_GET_ORDERS_DATA_'); $docid = $documentlist['MerchantDocumentInfo'][$i]['documentID']; $docs = array('string' => $docid); $ackorders = $t->postDocumentDownloadAck($t, $merchant,$docs); Any ideas of what I'm doing wrong are greatly appreciated. Similar TutorialsThis topic has been moved to Other Libraries and Frameworks. http://www.phpfreaks.com/forums/index.php?topic=319682.0 what's wrong in this line $tpl->set('main_content',set_block($heading,'center',$err_tpl->fetch(load_template('error.tpl')))); I am getting this error while building OOP portal.
Fatal error: Call to a member function count() on a non-object in C:\Users\Rishi\Documents\xampp\htdocs\PDO\Pitch_It\index.php on line 6
My index.php file:
<?php Hi, I have the following class: class User { private $_db; public function __construct($user = null) { $this->_db = DB::getInstance(); ....... } public function find($user = null) { if($user) { $field = (is_numeric($user)) ? 'id' : 'username'; $data = $this->_db->get('users', array($field, '=', $user)); if($data->count()) { ......... return true; } } return false; }In class DB I have: public static function getInstance() { if(!(self::$_instance)): self::$_instance = new self(); endif; return self::$_instance; }public function get() in class DB, after processing, returns $this, the single instance of class DB, this is assigned to $data which is then used to invoke public function count(), a member function of class DB. I am getting the following error: Fatal error: Call to a member function count() on a non-object. I would be very grateful if someone can point out my mistake. Hi, i'm having a problem with some coding ive done not too sure why I am getting the following error message Fatal error: Call to a member function escapeValue() on a non-object /commonResources/php.lib/validateForm.class.php on line 82 At first I thought it was my database class object wasn't being created, but double checked and I have create a new object called $database of the database class. Any ideas?? Code: [Select] <?php require_once ("/home/innova11/public_html/commonResources/dbConnection/dbConnection.php"); class validateForm { public $email, $fName, $surname, $addressLine1, $townCity, $county, $postcode, $contactNum, $comments, $recaptchaVal; public $resp; public $error; function validateRecaptcha2($recaptchaVal) { $this->recaptchaVal = $recaptchaVal; if(empty($this->recaptchaVal)) { return false; } else { $safe = $database->escapeValue($this->recaptchaVal); $sql = " SELECT * FROM test WHERE test = '".$safe."' "; $results = $database->sqlQuery($sql); if(mysql_num_rows($results)>0) { return true; } else { return false; } } } ?> i am tring to extend from DataAccess to Module... but is showing an error: location: Library/database.php <?php Class DatabaseAccess { public $db; public $sqlQuery; public function ConnectDB($host,$user,$password,$database){ $this->db = mysqli_connect($host,"",$password); if (mysqli_connect_errno()) { echo '<p>Cannot connect to DB: ' . mysqli_connect_error() . '</p>'; } $this->db &= mysqli_select_db($this->db,$database); } public function SqlQuery($sql) { return mysqli_query($this->db,$sql);//or die("Error:".mysqli_error()."<br />The Query:<b>$sql</b>"); } } ?> The Module class Location:Library/module.php <?php Class Module extends DatabaseAccess { public function DoInsert($tableName,$fields = array(),$values = array())//delete from table { $fields = implode(",", $fields); $values = implode("','", $values); return $this->db->SqlQuery ("INSERT INTO $tableName($fields) VALUES('$values')");//The error is here!!!!!!!!!!!!!!!! } } ?> and the controller file name: newProfile.php this is the cdode include "config.php"; include "Library/database.php"; include "Library/module.php"; $db = new DatabaseAccess; $db->ConnectDB(MYSQL_HOST_NAME,MYSQL_USER_NAME,MYSQL_PASSWORD,MYSQL_DATABASE);//define in config.php $db->Module = New Module; $db->Module->DoInsert("twitter_profiles", array(profile_user_name,profile_password,user_id), array($_POST['userName'],$_POST['password'],$userID));//DoInsert(tableName,Fields,Values) echo sysMessage("NewProfile.txt"); the error: Fatal error: /home/omerbsh/blalalala.com/tra/Library/module.php on line 59 the error is in the modle class where the comment: "The error is here!!!!!!!!!!!!!!!!" its cant to fine SqlQuery object but why??? thanks Hi I did something in phpmyadmin the other day and I cant my site back to work. please see the attatched pdf with print screens of what I did. Basically I was trying to add this: Code: [Select] INSERT INTO `PP088_config_options` ( `id` , `category_name` , `name` , `value` , `config_handler_class` , `is_system` , `option_order` , `dev_comment` ) VALUES ( NULL , 'general', 'installation_base_language', 'se_se', 'StringConfigHandler', '0', '12', NULL ); in one of the tables. When visiting www.konto.gradeup.se you will see the error message. I inserted the code from the DB.class.php file that I think is causing the problem. Code: [Select] */ static function escape($value) { return self::connection()->escapeValue($value); } // escape /** * Escape field / table name line 262 is the line with that starts with return self::connection Thanks so much in advance. Im novice at phpmyadmin Code: [Select] <?php /** * This function holds open database connections and provides interface to them. It is also used * for SQL logging * * @version 1.0 * @http://www.projectpier.org/ */ final class DB { /** ID of primary connection **/ const PRIMARY_CONNECTION_ID = 'PRIMARY'; /** * Collection of connections * * @var array */ static private $connections = array(); /** * ID of primary connection. This connection will be used if connection name is not suplied * * @var string */ static private $primary_connection = self::PRIMARY_CONNECTION_ID; /** * SQL log * * @var array */ static private $sql_log = array(); /** * This function will return specific connection. If $connection_name is NULL primary connection will be used * * @access public * @param string $connection_name Connection name, if NULL primary connection will be used * @return AbstractDBAdapter */ static function connection($connection_name = null) { if (is_null($connection_name)) { $connection_name = self::getPrimaryConnection(); } // if return array_var(self::$connections, $connection_name); } // connection /** * Create new database connection * * @access public * @param string $adapter Adapter name (currently only mysql adapter is implemeted) * @param array $params Connection params * @param string $connection_name Name of the connection, if NULL default connection ID will be used * @return boolean * @throws FileDnxError * @throws DBAdapterDnx */ static function connect($adapter, $params, $connection_name = null) { $connection_name = is_null($connection_name) || trim($connection_name) == '' ? self::PRIMARY_CONNECTION_ID : trim($connection_name); $adapter = self::connectAdapter($adapter, $params); if (($adapter instanceof AbstractDBAdapter) && $adapter->isConnected()) { self::$connections[$connection_name] = $adapter; return $adapter; } else { return null; } // if } // connect /** * This function will include adapter and try to connect. In case of error DBConnectError will be thrown * * @access public * @param string $adapter_name * @param array $params * @return AbstractDBAdapter * @throws DBAdapterDnx * @throws DBConnectError */ private function connectAdapter($adapter_name, $params) { self::useAdapter($adapter_name); $adapter_class = self::getAdapterClass($adapter_name); if (!class_exists($adapter_class)) { throw new DBAdapterDnx($adapter_name, $adapter_class); } // if return new $adapter_class($params); } // connectAdapter /** * Figure out adapter location and include it * * @access public * @param string $adapter_class * @return void */ private function useAdapter($adapter_name) { $adapter_class = self::getAdapterClass($adapter_name); $path = dirname(__FILE__) . "/adapters/$adapter_class.class.php"; if (!is_readable($path)) { throw new FileDnxError($path); } // if include_once $path; } // useAdapter /** * Return class based on adapter name * * @access public * @param string $adapter_name * @return string */ private function getAdapterClass($adapter_name) { return Inflector::camelize($adapter_name) . 'DBAdapter'; } // getAdapterClass // --------------------------------------------------- // Interface to primary adapter // --------------------------------------------------- /** * Try to execute query, ignore the result * * @access public * @param string $sql * @return true */ static function attempt($sql) { $arguments = func_get_args(); array_shift($arguments); $arguments = count($arguments) ? array_flat($arguments) : null; try { self::connection()->execute($sql, $arguments); } catch(Exception $e) { } return true; } // execute /** * Execute query and return result * * @access public * @param string $sql * @return DBResult * @throws DBQueryError */ static function execute($sql) { $arguments = func_get_args(); array_shift($arguments); $arguments = count($arguments) ? array_flat($arguments) : null; return self::connection()->execute($sql, $arguments); } // execute /** * Execute query and return first row from result * * @access public * @param string $sql * @return array * @throws DBQueryError */ static function executeOne($sql) { $arguments = func_get_args(); array_shift($arguments); $arguments = count($arguments) ? array_flat($arguments) : null; return self::connection()->executeOne($sql, $arguments); } // executeOne /** * Execute query and return all rows * * @access public * @param string $sql * @return array * @throws DBQueryError */ static function executeAll($sql) { $arguments = func_get_args(); array_shift($arguments); $arguments = count($arguments) ? array_flat($arguments) : null; return self::connection()->executeAll($sql, $arguments); } // executeAll /** * Start transaction * * @access public * @param void * @return boolean * @throws DBQueryError */ static function beginWork() { return self::connection()->beginWork(); } // beginWork /** * Commit transaction * * @access public * @param void * @return boolean * @throws DBQueryError */ static function commit() { return self::connection()->commit(); } // commit /** * Rollback transaction * * @access public * @param void * @return boolean * @throws DBQueryError */ static function rollback() { return self::connection()->rollback(); } // rollback /** * Return insert ID * * @access public * @param void * @return integer */ static function lastInsertId() { return self::connection()->lastInsertId(); } // lastInsertId /** * Return number of affected rows * * @access public * @param void * @return integer */ static function affectedRows() { return self::connection()->affectedRows(); } // affectedRows /** * Escape value * * @access public * @param mixed $value * @return string */ static function escape($value) { return self::connection()->escapeValue($value); } // escape /** * Escape field / table name * * @access public * @param string $field * @return string */ static function escapeField($field) { return self::connection()->escapeField($field); } // escapeField /** * Prepare string. Replace every '?' with matching escaped value * * @param string $sql * @param array $arguments Array of arguments * @return string */ static function prepareString($sql, $arguments = null) { if (is_array($arguments) && count($arguments)) { foreach ($arguments as $argument) { $sql = str_replace_first('?', DB::escape($argument), $sql); } // foreach } // if return $sql; } // prepareString // --------------------------------------------------- // Getters and setters // --------------------------------------------------- /** * Get primary_connection * * @access public * @param null * @return string */ static function getPrimaryConnection() { return self::$primary_connection; } // getPrimaryConnection /** * Set primary_connection value * * @access public * @param string $value * @return null * @throws Error if connection does not exists */ static function setPrimaryConnection($value) { if (!isset(self::$connections[$value])) { throw new Error("Connection '$value' does not exists"); } // if self::$primary_connection = $value; } // setPrimaryConnection /** * Add query to SQL log * * @access public * @param string $sql * @return void */ function addToSQLLog($sql) { self::$sql_log[] = $sql; } // addToSQLLog /** * Return SQL log * * @access public * @param void * @return array */ function getSQLLog() { return self::$sql_log; } // getSQLLog } // DB ?> I am just trying out PDO and I get this error, Fatal error: Call to a member function fetch() on a non-object, but isn't it already on the $this->db object? class shoutbox { private $db; function __construct($dbname, $username, $password, $host = "localhost" ) { # db conections try { $this->db = new PDO("mysql:host=".$hostname.";dbname=".$dbname, $username, $password); } catch(PDOException $e) { echo $e->getMessage(); } } function getShouts() { $sql_shouts = $this->db->query('SELECT shoutid, message, pmuserid, ipadress, time FROM shouts WHERE pmuserid == 0'); return $sql_shouts->fetch(PDO::FETCH_OBJ); } } When I use another class inside one class, I get this error Quote Call to a member function _safestring() on a non-object The code is here Code: [Select] <?php require ('db.inc.php'); $db = new db(); class common { function _cookiecheck() { if(!isset($_SESSION['username'])) { if(isset($_COOKIE['username'])&&isset($_COOKIE['password'])) { $pass = $db->_safestring($_COOKIE['password']); $user = $db->_safestring($_COOKIE['username']); $check = _query("select password from users where username='{$user}'"); if($check) { $_SESSION['username'] = $user; } } } } } ?> I get the error on the line when I call $db->_safestring(); Thanks for the help I have a database called "mp_users" with the following setup: Code: [Select] CREATE TABLE IF NOT EXISTS `mp_users` ( `id` int(10) unsigned default NULL auto_increment, `uid` int(10) unsigned NOT NULL, `username` varchar(100) NOT NULL, `email` varchar(50) NOT NULL, `points` int(10) unsigned NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1; When I try to run the following query, I get an error: Quote SELECT COUNT(id) AS user_exists FROM `mp_users` WHERE uid=$uid LIMIT 1; Error: Fatal error: Call to a member function query() on a non-object in /home/user/public_html/marketplace-functions.php on line 52 Here is the code: Code: [Select] <?php require_once "config.php"; $sql = new mysqli($db1['host'], $db1['user'], $db1['pass'], $db1['db']); function checkUserExists($uid){ // Query $q = "SELECT COUNT(id) AS user_exists FROM `mp_users` WHERE uid=$uid LIMIT 1;"; echo $q; $q = $sql->query($q); $r = $q->fetch_assoc(); // Any results? if($r['user_exists'] == 0){ // redirect to runonce... header('Location: marketplace.php?do=runonce&return='.urlencode($_SERVER['QUERY_STRING'])); exit(); } } ?> Line 52 is the $q query. I really cannot see what the problem is. The database exists, I've tried it in phpMyAdmin and it runs without trouble, but this wont! Can anyone help? Thanks in advance Random Error that im getting on my webhost, not localhost. Fatal error: Call to a member function fetch_assoc() on a non-object in /home/*****/index.php on line 127 Line 127: while ($premium = $row->fetch_assoc()) { Code: <div class="toplist-content"> <table cellspacing="0"> <tbody> <?php $row = $home->getList(1); while ($premium = $row->fetch_assoc()) { ?> <tr class="table"> <td class="name"><a href="server.html"> <h3> <?php echo ucfirst($premium['servername']); ?> </a> <font size='1.5'><?php echo ucfirst(substr($premium['serverdesc'],0,25)). "..."; ?> </h3> </font> </td> <td class="revision"><h3> <?php echo ucFirst($premium['revision']); ?> </h3></td> <td class="votes"><h3> <?php echo $premium['vote']; ?> </h3></td> <td class="status"><?php if($home->getStatus($premium['host'], $premium['port']) == true) { echo "<span class='ticket open'>Online</span>"; } else { echo "<span class='ticket closed'>Offline</span>"; } ?> </td> </tr> <?php } ?> </tbody> </table> </div> The getList() function : function getList($premium) { $query = $this->con->query("SELECT * FROM `".$this->prefix."servers` WHERE `premium` = '".$premium."' && `ban` = '0' ORDER BY (SELECT COUNT(*) FROM `".$this->prefix."votes` WHERE `serverId` = '".$this->prefix."servers.id') DESC") or die(mysqli_error()); return $query; } I am changing my script from connecting to the database within every function, to using one connection (in the main class). However, I am getting an error: Call to a member function query() on a non-object Here is the main class: <?php class main{ // the configuration vars public $config; // the current user variables public $uid = 0; // contains the user ID public $gid = 0; // contains the group ID // database variables public $DB; // contains the connection public $query_id; // contains the query ID public $query_count; // how many queries have there been? // cache variables public $cache; public $test = 'hi'; // initiate public function __construct(){ } // start up functions public function startup(){ // first, set up the caching if($this->config['use_memcache'] == true){ // start up cache require_once('cache.class.php'); $this->cache = new cache_TS(); } // now, set up the DB $this->connectToDatabase(); // now, set up the user session $this->setUserSession(); // are we logged in? If so, update our location if($this->uid > 0){ // update location $this->updateUserSession(); } } // connect to database public function connectToDatabase(){ // connect to database $this->DB = new mysqli($this->config['host'],$this->config['user'],$this->config['pass'],$this->config['db']); // were we able to connect? if(!isset($this->DB)){ // this is an error exit('could not connect to the database.'); } // test query $q = "SELECT id,title FROM topics WHERE id='1' LIMIT 1;"; $q = $this->DB->query($q); $r = $q->fetch_assoc(); echo $r['id'] . $r['title']; // send back return $this->DB; } // some removed.... The test query works fine. It fails he <?php class forum extends main{ public function viewTopic($tid){ // Connect To Database //$sql = new mysqli(db::$config['host'], db::$config['user'], db::$config['pass'], db::$config['db']); // Get assorted details (topic, forum, etc) // Get topic details $tid = intval($tid); $tq = "SELECT * FROM `topics` WHERE id='$tid' LIMIT 1"; $tq = $this->DB->query($tq); $tr = $tq->fetch_assoc(); startup in main has already been called before forum is. The DB connects without failure. Can anyone see what the problem is? How can I get $this->DB->query to work? (The query works fine when it's ran in the main class) i am really struggling and i have no idea what to do. Call to a member function stmt_init() on a non-object on this code. if (isset($_POST['insert'])) { require_once('includes/connection.php'); // initialize flag $OK = false; // create database connection $conn = dbConnect('write'); // initialize prepared statement $stmt = $conn->stmt_init(); // create SQL i am using a book but i have tried it many ways and the same error occurs. i have looked on forums and they say that i have not set up the users correctley. but for a test i give my user all the permitions that i could and same problem. the error occurs on this line $stmt = $conn->stmt_init(); with the error message stating Call to a member function stmt_init() on a non-object please if you have seen this before could you help thanks in advance Hello, I have the situation shown below in the code: if(//condition is met) { $val = new Val(); $valon = $val->check($_POST, array(.........)); } if($valon->passes()) { $use = new Use(); ........ } //check() and passes() both belong to class Val public function check($source, $items = array()) { ...................... return $this; }I get the following warning and error: Notice: Undefined variable: valon and Fatal error: Call to a member function passes() on a non-object I can't see anything wrong with the code. check() returns an object of class Val which is assigned to $valon, $valon then calls a member function of class Val. Could you please help. Please let me know whether to include further code. Code: [Select] <?php class OnlineStore { private $DBConnect = NULL; private $storeID = ""; private $inventory = array(); private $shoppingCart = array(); function __construct() { include("inc_OnlineStoreDB.php"); $this->DBConnect = $DBConnect; } function __destruct() { if (!$this->DBConnect->connect_error) $this->DBConnect->close(); } public function setStoreID($storeID) { if ($this->storeID != $storeID) { $this->storeID = $storeID; $SQLstring = "SELECT * FROM inventory " . " where storeID = 'jw" . $this->storeID . "'"; $QueryResult = $this->DBConnect->query($SQLstring); if ($QueryResult === FALSE) { $this->storeID = ""; } else { $this->inventory = array(); $this->shoppingCart = array(); while (($Row = $QueryResult->fetch_assoc()) !== NULL) { $this->inventory[$Row['productID']] = array(); $this->inventory[$Row['productID']]['name'] = $Row['name']; $this->inventory[$Row['productID']]['description'] = $Row['description']; $this->inventory[$Row['productID']]['price'] = $Row['price']; $this->shoppingCart[$Row['productID']] = 0; } } } } public function getStoreInformation() { $retval = FALSE; if ($this->storeID != "") { $SQLstring = "SELECT * FROM store_info " . " WHERE storeID = '" . $this->storeID . "'"; $QueryResult = @$this->DBConnect->query($SQLstring); if ($QueryResult !== FALSE) { $retval = $QueryResult->fetch_assoc(); } } return($retval); } public function getProductList() { $retval = FALSE; $subtotal = 0; if (count($this->inventory) > 0) { echo "<table width='100%'>\n"; echo "<tr><th>Product</th><th>Description</th>" . "<th>Price Each</th><th># in Cart</th>" . "<th>Total Price</th><th> </th></tr>\n"; foreach ($this->inventory as $ID => $Info) { echo "<tr><td>" . htmlentities($Info['name']) . "</td>\n"; echo "<td>" . htmlentities($Info['description']) . "</td>\n"; printf("<td class='currency'>$%.2f</td>\n", $Info['price']); echo "<td class='currency'>" . $this->shoppingCart[$ID] . "</td>\n"; printf("<td class='currency'>$%.2f</td>\n", $Info['price'] * $this->shoppingCart[$ID]); echo "<td><a href='" . $_SERVER['SCRIPT_NAME'] . "?PHPSESSID=" . session_id() . "&ItemToAdd=$ID'>Add " . " Item</a></td>\n"; $subtotal += ($Info['price'] * $this->shoppingCart[$ID]); } echo "<tr><td colspan='4'>Subtotal</td>\n"; printf("<td class='currency'>$%.2f</td>\n", $subtotal); echo "<td>$nbsp;</td></tr>\n"; echo "</table>"; $retval = TRUE; } return($retval); } public function addItem() { $ProdID = $_GET['ItemToAdd']; if (array_key_exists($ProdID, $this->shoppingCart)) $this->shoppingCart[$ProdID] += 1; } } ?> having an issue to where nothing is appearing on the page and getting the Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\PHP\Chapter.10\class_OnlineStore.php on line 24 HERE IS THE MAIN PAGE Code: [Select] <?php session_start(); require_once("class_OnlineStore.php"); $storeID = "COFFEE"; $storeInfo = array(); if (class_exists("OnlineStore")) { if (isset($_SESSION['currentStore'])) $Store = unserialize($_SESSION['currentStore']); else { $Store = new OnlineStore(); } $Store->setStoreID($storeID); $storeInfo = $Store->getStoreInformation(); } else { $ErrorMsgs[] = "The OnlineStore class is not available!"; $Store = NULL; } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title><?php echo $storeInfo['name']; ?></title> <link rel="stylesheet" type="text/css" href="<?php echo $storeInfo['css_file']; ?>" /> </head> <body> <h1><?php echo htmlentities($storeInfo['name']); ?></h1> <h2><?php echo htmlentities($storeInfo['description']); ?></h2> <p><?php echo htmlentities($storeInfo['welcome']); ?></p> <?php $Store->getProductList(); $_SESSION['currentStore'] = serialize($Store); ?> </body> </html> I HAVE REVIEWED IT OVER AND OVER AGAIN AND I CANT SEE THE PROBLEM. MAYBE SOMEONE FROM THE OUTSIDE CAN HELP OUT. can anyone tell me why im getting this error? Fatal error: Call to a member function fetchrow() on a non-object code being used..... Code: [Select] $comment_query = mysql_query("SELECT * FROM `comments` where video_id='$video[0]' ORDER BY='desc' LIMIT='30'"); while($comments = $comment_query->fetchrow()) { here is my php code. i want to remove the attribute of a tag and then add a new attribure to the tag. simply i want attribute validation. but this code gives me the following error. "Fatal error: Call to a member function getAttributeNode() on a non-object in D:\wamp\www\ReadXml\new.php on line 35" <?php $xml = new DOMDocument(); $doc->recover = true; $xml->load('test.xml'); $node = $xml->getElementsByTagName('*'); $nodename = ""; $node_name = array(); $att = ""; $attr_name = ""; $attr_value = ""; foreach($node as $value) { echo "<HTML><Head>"; echo "<title> Getting Attribute Example</title>"; echo "</Head><body><B>"; echo "Node Name is :".$value->nodeName; echo "<br /><br /></B></body></HTML>"; $nodename = $value->nodeName; $node_name = $xml->getElementsByTagName('$nodename')->item(0); echo $nodename; $att = $node_name->getAttributeNode('name'); //Line No 35 echo "<HTML><Head>"; echo "<title> Getting Attribute Example</title>"; echo "</Head><body><B>"; echo "Node Name is :".$att->name; echo "<BR>Attribute Value is :".$att->value; echo "<br /><br /></B></body></HTML>"; $attr_name = $att->name; $attr_value = '"' . $att->value . '"'; $nodename->removeAttributeNode('$attr_name'); $nodename->setAttributeNode(new DOMAttr('$attr_name', 'hello')); $nodename->setAttribute(new DOMAttr('$attr_name', '$attr_name')); $xml->save('temp2.xml'); } ?> Hi all, I'm getting the following error, but I cannot see why: ERROR: Fatal error: Call to a member function fetch_assoc() on a non-object in {filepath} on line 36 CODE: Code: [Select] <?php ini_set('display_errors',1); error_reporting(E_ALL); require_once("aconfig.php"); $eid = $_GET["event"]; echo '<html> <head> <title>Admin Control Panel :: PRINT TICKETS</title> <style type="text/css"> body { font-family: Helvetica, Arial; } </style> </head> <body>'; //start classes $db = new db(); //connect to DB //attempt it $sql = new mysqli(db::$config['host'], db::$config['user'], db::$config['pass'], db::$config['db']); //check for ERR if (mysqli_connect_errno()) { printf("Connect failed: %s\n", mysqli_connect_error()); exit(); } // if($eid == "edit"){ echo '<h1>SELECT EVENT</h1> <p>Select an event to print tickets for</p> <p>'; $query = 'SELECT * from `tickets` ORDER by id'; $query = $sql->real_escape_string($query); // Perform Query $result = $sql->query($query); // Loop Through Result while ($row = $result->fetch_assoc()) { echo '− <a href="ptickets.php?event='.$row[id].'">'.$row[event_name].'</a> <br />'; } echo '</p>'; }else { $query2 = 'SELECT * from `orders` WHERE `id` = '.$eid.', paid = "1"'; $query2 = $sql->real_escape_string($query2); // Perform Query $result2 = $sql->query($query2); // Loop Through Result while ($row2 = $result2->fetch_assoc()) { echo '<table cellspacing="1" cellpadding="1" border="1" width="400"> <tbody> <tr> <td colspan="2"><strong>Online Ticket</strong></td> </tr> <tr> <td width="300"> <p>Event: <strong>'.$row2[eventname].'</strong></p> <p>Holder Name: <strong>'.$row2[name].'</strong></p> <p>No. Adult tickets: <strong>'.$row2[adult_tix].'</strong><br /> No. Concession tickets: <strong>'.$row2[concess_tix].'</strong></p> </td> <td> <p><u>STAFF</u></p> <p><em>Rip this side off once ticket holder has entered.</em></p> </td> </tr> </tbody> </table> <p> </p>'; } } echo '</body></html>'; ?> What the script does: if the page is ?event=edit, it lists all the available events. If not, it checks what event id is at ?event and lists that ID from the DB. What's wrong with it? Thanks Hey all. I am trying to make a mod for our fantasy football site but keep getting an error. Fatal error: Call to a member function Execute() on a non-object in C:\Inetpub\wwwroot\phpffl\program_files\autorun\general\top_team.php on line 8. Here is the code. <?php global $PHP_SELF, $DB; $leagues_ID='1'; $week='2'; $week_ID=$week -1; $game_ID=$week_ID; $sql="select ID, team_name from teams where leagues_ID='$leagues_ID';"; [b] $teams_rs=$DB->Execute($sql);[/b] while (!$teams_rs->EOF) { $top_team_ID=$teams_rs->fields('ID'); $top_team_name=$teams_rs->fields('team_name'); $top_team_points=get_total_points_game($top_team_ID, $week_ID, $week_ID, $leagues_ID); //echo $top_team_points." "; $top_team_points_array[$top_team_name]=$top_team_points; $teams_rs->MoveNext(); } $top_scoring_team_ID=""; $top_scoring_team_name=""; $top_scoring_points=""; foreach(array_keys($top_team_points_array) as $key) { if ($top_team_points_array[$key] > $top_scoring_points) { $top_scoring_points=$top_team_points_array[$key]; //$top_scoring_team_ID=$top_team_ID; $top_scoring_team_name=$key; } } $sql="insert into total_scores (team_ID, teams_name, week_id, total_score, leagues_ID) values('$top_team_ID', '$top_scoring_team_name', '$week_ID', '$top_scoring_points', '$leagues_ID');"; $rs=$DB->Execute($sql); echo "<br>"; echo "<br>"; echo "Weekly Top Scoring Team for Week $week_ID is: $top_scoring_team_name with a score of $top_scoring_points points!"; echo "<br>"; echo "<br>"; //print_r ($top_team_points_array); echo "<br>"; echo "<br>"; $weekly_top_score=max($top_team_points_array); ?> I have a function in the global file looks like this. /************** BEGIN ADDITIONAL FUNCTIONS **************************/ function get_top_scoring_teams() { global $PHP_SELF, $DB, $PHPFFL_IMAGE_PATH; $sql="select * from total_scores order by week_ID DESC limit 1;"; $teams_rs=$DB->Execute($sql); while (!$teams_rs->EOF) { $team_ID=$teams_rs->fields('team_ID'); $team_name=$teams_rs->fields('teams_name'); $team_points=$teams_rs->fields('total_score'); $week_ID=$teams_rs->fields('week_ID'); echo "The Top Scoring Team for <strong>Week $week_ID</strong> was <br><img src='{$PHPFFL_IMAGE_PATH}team_logos_standings/$team_ID.gif'><br> <strong>$team_name</strong> with a score of <strong>$team_points</strong> points. <hr>"; $teams_rs->MoveNext(); } } /************** BEGIN ADDITIONAL FUNCTIONS**************************/ Any one see what the issue might be? I am running this on a windows 2003 server with iis 6 php 5.3 and mysql 5.1.5 Any help would be appreciated. Thanks Hitster4 Hello guys I'm pulling out my last remaining hairs with this PHP problem. I'm not really good at PHP but I'm trying to do some changes to a script as instructed by the developer, but apparently I got some wrong instructions. The error I get is: Fatal error: Call to a member function postage_country_display() on a non-object in file.php on line 34 I've been searching the web high and low and can't seem to find a solution. Does anyone have a hint at what might be wrong? Here is the code that's causing the problem and the class. Code: Code: [Select] $template->set('items_id', intval($_REQUEST['items_id'])); $item_details = $db->get_sql_row("SELECT * FROM " . DB_PREFIX . "items WHERE items_id='" . intval($_REQUEST['items_id']) . "'"); $unCountryPrice = unserialize(stripslashes($db->add_special_chars($item_details['country_postage']))); // print_r($unCountryPrice); $postageCountry = $item->postage_country_display($unCountryPrice,$item_details['currency']); $template->set('postageCountry', $postageCountry); $template->set('item_details', $item_details); And here is the class: Code: [Select] function postage_country_display($unCountryPrice,$currency) { if (is_array($unCountryPrice)) { $postageCountry = "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> "; $fees = new fees(); while (list($k,$v)= each($unCountryPrice)){ $cQueyr = $this->query("SELECT a.name as name1,b.name as name2 FROM " . DB_PREFIX . "countries a LEFT JOIN " . DB_PREFIX . "countries b ON (a.parent_id = b.id) WHERE a.id = '". $k ."'"); $cRow = $this->fetch_array($cQueyr); $postageCountry.="<tr><td>". ($cRow['name2']==""?$cRow['name1']:$cRow['name2'].' > '.$cRow['name1']) ."</td><td> ".$currency.' '.number_format($v,2)."</td></tr>"; } $postageCountry.="</table>"; } return $postageCountry; |