donglong2856 2014-10-19 10:48
浏览 62

注意:尝试在php中获取非对象的属性[重复]

This question already has an answer here:

I have a problem in userpie login and register script. So the script works good using lamp on linux mint! But when I go on windows there is more than 15 problem, one of them is

Notice: Trying to get property of non-object in C:\armadicehost\htdocs\models\funcs.user.php on line 164

Notice: Trying to get property of non-object in C:\armadicehost\htdocs\models\funcs.user.php on line 165

This is the code that line 165 and 164 have:

function isUserLoggedIn()
{
    global $loggedInUser,$db,$db_table_prefix;

    $sql = "SELECT user_id,
              password
            FROM ".$db_table_prefix."users
            WHERE user_id = '".$db->sql_escape($loggedInUser->user_id)."'
                AND password = '".$db->sql_escape($loggedInUser->hash_pw)."' 
            AND
            active = 1
            LIMIT 1";
            }

    if($loggedInUser == NULL)

And for login.php it says...

Notice: Undefined index: status in C:\armadicehost\htdocs\login.php on line 401

    <?php
    if(!empty($_POST))
    {
    ?>
    <?php
    if(count($errors) > 0)
    {
    ?>

    <?php
            } }
    ?> 

I need to fix this please any idea about them?

</div>
  • 写回答

3条回答 默认 最新

  • drqrdkfue521903877 2014-10-19 10:57
    关注

    It seems that due to your logic, $loggedInUser is not initialized properly. "non-object" in that case means that it is either null or not an object (i.e. it is a string or a number ...).

    Try to change:

    function isUserLoggedIn()
    {
        global $loggedInUser,$db,$db_table_prefix;
    
        if ( !isset($loggedInUser) || !isset($db) || !isset($db_table_prefix) )
        {
             throw new Exception "Objects and/or globals not initialized.";
        }
    
        $sql = "SELECT user_id,
        .....
    

    This will terminate your script if things are going wrong. Since the rest of code is missing, it's almost impossible to tell where exactly the problem resides.

    To your second Q: this seems not to be the proper code since there is no array reference with an index 'status'

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?