0
I have other examples here but none worked for me
I have an instruction to pull an image from the database, only it’s giving the error
"Notice: Trying to get Property of non-object in ...";
$q= $db->Select("produto", "nome, imagem", "WHERE id = 21 AND masterid = 100");
if($q){
$prod= mysqli_fetch_assoc($q);
$thumb = $prod->imagem;
}
What do I do to fix it?
Notice: Trying to get Property of non-object in /home/.../.../public_html/sistema/.../.../.../header.php on line 6 [SOLVED THE PROBLEM ABOVE]
Another thing, guys.
Solved the above problem about Non-object, I want to pass the value of this variable:
$thumb = str_replace("../", "http://www.siteexemplohere.com/", ($prod['imagem']));
That is, the value of $Thumb, for the:
<meta property="og:image" content="<?php echo $thumb ? $thumb : " <?php echo $Raiz; ?>/assets/img/thumbs/default.png "; ?>"/>
because I want the user to click on the share button Facebook, the share box appears the product picture + product description (that’s quiet);
I followed the documentation and it doesn’t work... Thanks for the help you are giving me... Each hint an idea to formulate another solution of the problem
Remembering that when I give a var_dump(), he is picking up from the bank normally, I already var_dump $Thumb after being picked up from the bank and after being inserted in the "meta".
Pass the entire error code, this will show on which line exactly is the problem.
– David Alves
What the error indicates is that
$prod
is not an object and so can not do->imagem
. It is easy to confirm this by doingvar_dump($prod);
on the line before the error.– Isac
@Isac and how to fix it?
– Lougans de Matos
First, using the
var_dump
to know what we are dealing with. Then, see how it was implemented$db
, to know what is the return ofSelect
.– Woss
Tip: Can you replace <?php echo $variable ? > with <?=$variable ? >. Just enable short_tags in php.ini
– eliangela
Aaah yes this already tlg
– Lougans de Matos
Another thing, when I said you could change your question and add the code, I thought the error was in the same snippet, kkk
– eliangela
Ok, rsrs... But this problem Do you know how to solve? has some ideiw
– Lougans de Matos
After that instruction echo $Thumb ? $Thumb : has a mistake. The right is:
<meta property="og:image" content="<?php echo $thumb ? $thumb : echo "{$Raiz}/assets/img/thumbs/default.png"; ?>"/>
. You are already inside the PHP tag. No need to open another.– eliangela
@eliangela For information purposes only, the tag
<?= ?>
is not a short tag, then you don’t need to enable it. It works by default since version 5.4. A short tag is just<? ?>
; I commented on that in this answer.– Woss
I didn’t know that. Thank you, @Andersoncarloswoss
– eliangela