我不断收到执行该代码时出现以下错误信息:
注:试图获得非对象的属性在C:\ WAMP \ WWW \ HoneysProject \ function.php上线1178PHP投掷奇数错误
1178行是指以下代码行:
$ number_photos = $ photo_exists-> num_rows;
不确定它为什么抛出这个错误,因为它是我在这个项目上频繁使用的一行代码的重复。自从我继续输出成功后,似乎对运行完成的代码没有任何实际影响。会像错误信息停止弹出。
以下是源代码,在它的全部内容:
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>' ;
}
}
呃......是'$ photo_exist'对象? –
当你var_dump($ number_photos)时会发生什么,它实际上是一个对象吗? –
这并不奇怪 – Ryan