This question already has an answer here:
Trying to get property of non-object in PDO
(1 answer)
Closed 6 years ago.
I am selecting one column from Member table. Now I want to get the value from this column. But when I try to get the value I am getting an exception as :
<br />
<b>Notice</b>: Trying to get property of non-object in
<b>C:\Program Files (x86)\Ampps\www\MLMapi\PurchaseProduct.php</b> on line
<b>54</b>
<br />
Code:
$stmt = $dbConnection->prepare("select Member.sales_hold_fund from Member where member_id=?");
$stmt->execute(array($member_id));
$member = $stmt->fetch(PDO::FETCH_ASSOC);
$fund = $member-> sales_hold_fund;// line54
$sales_hold_fund = $fund + $amount;
I want to get the sales_hold_fund value from database and add the amount value to the sales_hold_fund.
member value :
"Member": {
"sales_hold_fund": "1000"
}
Can anyone help please? Thank you..
try
$fund = $member['sales_hold_fund'];
Related
This question already has answers here:
How to force PDOStatement->fetchAll to return array of objects?
(3 answers)
Closed 3 years ago.
I'm getting an error and I don't really know where is the issue. Please can anybody show me what is wrong? I would appreciate any assistance, thanks!
Trying to get property of non-object in on line 20
class.php
class PostsData extends dbh {
public function fetchAllPosts() {
$sql = "SELECT * FROM post";
$stmt = $this->connect()->query($sql);
$stmt->execute([]);
$result = $stmt->fetchAll();
return $result;
} }
blog.php
$post_ = new PostsData;
$allposts = $post_->fetchAllPosts();
foreach ($allposts as $post) {
echo $post->post_title; //error
You are not checking if the result returned is null or not. The error would be generated if it is because there will be no property to access altogether.
Consider a print statement in FetchAllPosts function to check if you get any rows returned. That may help narrow down the scope of the error.
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
I seem to be receiving a number of php notices advising 'Trying to get property of non-object'.
I assume it is the way I have structured the mysql statement but I am a little unsure and I am after assistance here.
The function is as follows:-
public function getPreviousBlock($iHeight=0) {
$stmt = $this->mysqli->prepare("
SELECT height
FROM " . $this->block->getTableName() . "
WHERE height < ?
ORDER BY height DESC
LIMIT 1");
if ($this->checkStmt($stmt) && $stmt->bind_param('i', $iHeight) && $stmt->execute() && $result = $stmt->get_result())
return $result->fetch_object()->height;
return $this->sqlError();
}
Any help would be much appreciated.
fetch_object() will return NULL if there are no more rows in the result set. Of course NULL is not an object so you will get this error.
So you need to check for example:
$obj = $result->fetch_object();
if ($obj) {
return $obj->height;
} else {
return null;
}
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 5 years ago.
enter image description hereI make a one function to fetch the data from database in php.I used the return value of another function for select the id from the database.But when i store worker id into array i get the error "Trying to get property of non-object" like this.What i do?I wan to store match id according to query into one array.
public function getWorkers()
{
$db = JFactory::getDBO();
$orderid=$this->getTodayOrder();
$workersId=array();
foreach($orderid as $workers1)
{
$query2 = "SELECT * FROM #__orderassignment WHERE orderid='".$workers1."'";
$db->setQuery($query2);
$result1 = $db->loadObjectList();
$workersId[]=$workers1->workers;
}
return $workersId;
}
if array is given then you need to access it like this
$workersId[]=$workers1['workers'];
This question already has answers here:
Fatal error: Call to a member function fetch_assoc() on a non-object [duplicate]
(4 answers)
Closed 7 years ago.
<?php $results = DB::select('select * from insurance_policy where Id = ?', [1]);
$row = $results->fetch_assoc();
echo $row["Amount"];
?>
Here is my code it is giving me a error:Call to a member function fetch_assoc() on a non-object.
I am using Laravel 5
DB::select would return an Array which stores the DB rows.
You can iterate the results
foreach ($results as $row) { echo $row['Amount']; }
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
check when PDO Fetch select statement returns null
(2 answers)
Closed 9 years ago.
I am a beginner with php and PDO and need help solving this error that I keep getting on this line of code
$category_name [$category["category_id"]] = $category["category"]; I continue to get, Notice: Undefined index: category. Also Undefined index: category_id. I dont have a clue as to why, could someone provide me with the correct way to do this. Here is my code. This one slightly different because it used in a while statement.
// get the item category names
$category_name = Array();
$query = 'SELECT * FROM category_2';
$categories_list = $db->prepare($query);
$categories_list->execute();
while ($category = $categories_list->fetchAll())
{
$category_name [$category["category_id"]] = $category["category"];
}
try this:
We will have single array in each time in loop in $category. You can access any database attributes in this array like this: $category['attribute_name']
while ($category = $categories_list->fetch(PDO::FETCH_ASSOC))
{
$category_name [$category["category_id"]] = $category["category"];
}
print_r($category_name);
You're probably looking for fetch(PDO:: FETCH_ASSOC) instead of fetchAll()