php 注意:尝试在 C:\xampp\htdocs\ 中获取非对象的属性

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16165320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 10:38:25  来源:igfitidea点击:

Notice: Trying to get property of non-object in C:\xampp\htdocs\

phpmysql

提问by user2279037

While executing this code it gives an error message which i don't have any idea about. I did goooooogle, but I didn't find any solution.

在执行此代码时,它给出了一条我不知道的错误消息。我做了goooooogle,但我没有找到任何解决方案。

**Notice: Trying to get property of non-object in C:\xampp\htdocs**

**注意:尝试在 C:\xampp\htdocs 中获取非对象的属性**

<?php
    $_REQUEST['PropertyID'];
    $_REQUEST['PropertyImageID'];
    $propertyImageID=$_GET['PropertyImageID'];
    $PropertyID=$_GET['PropertyID'];
    require_once('db.php');
    $propertyquery = "SELECT PropertyImageID, PropertyName, PropertyStatus, PropertyLocation, PropertyRegion FROM properties WHERE PropertyImageID =$propertyImageID";
     $propertyquery_run = $connection->query($propertyquery);
    if ($propertyquery_run-> num_rows > 0) 
    {
        while ($propertyrow = $propertyquery_run-> fetch_assoc()) 
          {
        $imagequery = "SELECT PropertyImageID, ImagePath FROM propertyimages WHERE PropertyImageID = $PropertyID";
         $imagequery_run = $connection->query($imagequery);       
    ?>
            <table style="margin-left:348px;">
    <tr><td>PropertyName:</td><td><span style="color:#0F0; font-weight:bold;"><?php echo htmlentities($propertyrow['PropertyName']) ?></span></td></tr>
    <tr><td>PropertyStatus:</td><td><span style="color:#0F0; font-weight:bold;"><?php echo htmlentities($propertyrow['PropertyStatus']) ?></span></td></tr>
    <tr><td>PropertyLocation:</td><td><span style="color:#0F0; font-weight:bold;"><?php echo htmlentities($propertyrow['PropertyLocation']) ?></span></td></tr>
    <tr><td>PropertyRegion:</td><td><span style="color:#0F0; font-weight:bold;"><?php echo htmlentities($propertyrow['PropertyRegion']) ?></span></td></tr>
            </table>
        <center>
    <?php 
                if($imagequery_run -> num_rows > 0)  
                {
                    while ($imagerow = $imagequery_run-> fetch_assoc())  
                    {
                    ?>
                       <div style="border:solid 2px #9F0; border-radius:5px; height:222px; width:544px;">
                       <img src="<?php echo htmlentities($imagerow['ImagePath'])  ?>" width="544" height="222" >
                       </div><br />    
                    <?php
                    }
                    }

                }
            }
    ?>

回答by ibi0tux

This notice occurs when you're using a non-object variable as an object. You're probably using : $a -> b?like syntax on a variable $a?which is not an object.

当您将非对象变量用作对象时,会出现此通知。您可能$a -> b在变量上使用 : ?like 语法$a?它不是一个对象。

Make sure $propertyquery_run, $imagequery_run... are objects which have properties you're using.

确保$propertyquery_run, $imagequery_run... 是具有您正在使用的属性的对象。

Edit :

编辑 :

If the error is here $imagequery_run -> num_rows > 0. This means $imagequery_runis not an object that have num_rowsproperties. Maybe it's NULL. Check its value before the test.

如果错误在这里$imagequery_run -> num_rows > 0。这意味着$imagequery_run不是具有num_rows属性的对象。也许它是NULL。在测试前检查其值。

$imagequery = "SELECT PropertyImageID, ImagePath FROM propertyimages WHERE PropertyImageID = $PropertyID";
$imagequery_run = $connection->query($imagequery);       
if(!$imagequery_run)
{
     // do what you want
}