可能重複:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in錯誤獲取陣列
在我的詳細視圖頁面,並抓住正確的ID在地址欄,就像這樣:
http://localhost/attractions/details.php?ID=1
我的頁面標題和邊欄加載,但在我想要我的記錄細節的空間中,我得到這個錯誤一團糟年齡:
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/attractions/details.php on line 41
這是'details.php頁面代碼(用了不必要的html刪除):
<?php
include 'page-start.php';
$myQuery = "SELECT Attraction.*, Type.TypeName ";
$myQuery .= "FROM Attraction ";
$myQuery .= "INNER JOIN Type ON Attraction.Type = Type.TypeID";
$myQuery .= "WHERE AttractionID=" . $_GET['ID'];
$result = mysql_query($myQuery);
if (!result) {
die('Query error: ' . mysql_error());
}
?>
<body>
<div class="container">
<h2>List of Attractions</h2>
<?php
//display attractions row by row
while($row = mysql_fetch_array($result))
{
echo '<div class="attraction">';
echo '<h4><a href="details.php?ID=' . $row['AttractionID'] . '">' . $row['Name'] . '</a></h4>';
echo '<div class="featureimage">';
echo '<img src="'. $row['ImageUrl'] . '" />';
echo '</div>';
echo '<p>' . $row['TypeName'] . '</p>';
echo '<h5>' . $row['Summary'] . '</h5>';
echo '</div>';
}
?>
</div><!-- container -->
</body>
</html>
<?php
include 'page-end.php';
?>
41號線是這一行:
while($row = mysql_fetch_array($result))
我只知道我會在這裏忽略這麼簡單的東西,但是我被困住了,我真的無法弄清楚是什麼原因導致了錯誤,請讓我看看我的情況,我已經搜索過類似的問題,但沒有Ť帽子可以幫助我!
http://localhost/attractions/details.php?ID = 1顯然不起作用;) – Phorce
您在'if(!result)'中缺少'$'。 – deceze
你也很容易** SQL注入**。見http://kunststube.net/escapism。 – deceze