doushao6874 2014-02-13 08:30
浏览 44
已采纳

PHP抛出奇怪的错误[关闭]

I keep getting the following error message when executing this code:
Notice: Trying to get property of non-object in C:\wamp\www\HoneysProject\function.php on line 1178

Line 1178 is referring to the following line of code:
$number_photos = $photo_exists->num_rows ;

Not sure exactly why it is throwing this error because it's a duplicate of a line of code I've been using pretty frequently on this project. Doesn't seem to have any real influence on the code running to completion since I proceed to the successful output. Would Just like the error message to stop popping up.

The following is the source code in it's entirety:

function create_album()
{
    try
    {
        if( isset( $_SESSION['session_id'] ) && $_SESSION['permissions'] ==  0  )
        {
            if( isset( $_POST['album_name'] ) && ( file_exists( $_FILES['cover_photo']['tmp_name'] ) || is_uploaded_file($_FILES['cover_photo']['tmp_name'] ) ) )
            {
                $db = honneyconnect( ) ;
                if( mysqli_connect_error() )
                {
                    throw new Exception( "Could not connect to the database") ;  
                }
                else
                {
                    $unique = false ;
                    while( $unique == false )
                    {
                        $key = rand( )  ;
                        $query = "select * from albums where album_id = '".$key."'";  
                        $album_exists = $db->query( $query ) ;
                        $number_albums = $album_exists->num_rows ;
                        if( $number_albums == 0 )
                        {
                            $unique = true ;
                        }
                    }
                if( !mkdir( "c:\\wamp\\www\\honeysproject\\".$_POST['album_name']  ) )
                {
                    throw new Exception( "Failed to create the album.  Please try again." ) ;
                }
                else
                {
                    $file_name = $_FILES["cover_photo"]["name"] ;
                    if( !move_uploaded_file($_FILES["cover_photo"]["tmp_name"], "C:/wamp/www/HoneysProject/".$_POST['album_name']."/" . $_FILES["cover_photo"]["name"]) )
                    {
                        throw new Exception( "There was a problem uploading the file" ) ;
                    }
                    else
                    {
                        $query = 'insert into albums values ("'.$key.'","'.$_POST['album_name'].'", "'.$_FILES['cover_photo']['name'].'")';
                        $album = $db->query( $query ) ;
                        if( !$album )
                        {
                            throw new Exception( "Failed to create the ".$_POST['album_name']." album.  Please check your input and try again." ) ;
                        }
                        else
                        {
                            $unique = false ;
                            while( $unique == false )
                            {
                                $picture_key = rand();
                                $query = "select * from photos where photo_id = '".$picture_key."'" ;
                                $photo_exists = $db->query( $query ) ;
                                $number_photos = $photo_exists->num_rows ;
                                if( $number_photos == 0 ) 
                                {
                                    $unique = true ;
                                }


                            }
                            $query = "insert into photos values ('".$key."', '".$picture_key."', '".$file_name."')" ;
                            $picture_query = $db->query( $query ) ;
                            if( !$picture_query ) 
                            {

                                throw new Exception( "Failed to add photo to the photos table.  Please check your syntax and try again." ) ;

                            }   
                            else
                            {
                                echo "<table><tr><td><img src='/HoneysProject/".$_POST['album_name']."/".$_FILES['cover_photo']['name']."'></td><td><a class ='button' href='/HoneysProject/uploadphotos.php?album_id=".$key."'>Upload Photos</a><br><a class='button' href='/HoneysProject/albumedit.php?album_id=".$key."'>Edit Album</a></td></tr></table>" ;
                            }
                        }
                    }

                }


            }
        }
        else
        {
            echo '<div class="data_entry">
                        <form id="new_album" method="post" action="createalbum.php" enctype="multipart/form-data" />
                        <input type="hidden" name="MAX_FILE_SIZE" value="50000000" />
                        <table>
                        <tr><td>Album Name:</td><td><input type="text" size="10" name="album_name" /></td></tr>
                        <tr><td>Choose a Default Photo:</td><td><input type="file" name="cover_photo" id="photo" /></td></tr>
                        <tr><td><input type="submit" value="Submit Data" /></td></tr>
                        </table>

                        </form></div>' ;
        }
    }
}
catch( Exception $error ) 
{
    echo "<div class='error'>".$error."</div>" ;
    echo '<div class="data_entry">
                        <form id="new_album" method="post" action="createalbum.php" enctype="multipart/form-data" />
                        <input type="hidden" name="MAX_FILE_SIZE" value="50000000" />
                        <table>
                        <tr><td>Album Name:</td><td><input type="text" size="10" name="album_name" value="'.$_POST['album_name'].'"/></td></tr>
                        <tr><td>Choose a Default Photo:</td><td><input type="file" name="cover_photo" id="photo" /></td></tr>
                        <tr><td><input type="submit" value="Submit Data" /></td></tr>
                        </table>

                        </form></div>' ;

}
}
  • 写回答

3条回答 默认 最新

  • dongshun7312 2014-02-13 08:46
    关注

    The error is due to an unsuccessful query.

    I wonder why you are manually generating the entities keys? Doesn't your DBMS support auto incremented keys or sequences?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.