我正在設計一個網站,它允許用戶註冊和登錄 - 登錄後,用戶會看到其他鏈接(僅對註冊用戶可見)。其中一個環節包括, 「我的書籤」 - 「我的書籤」(的index.php)的代碼如下:mysql_fetch_array()&mysql_free_result()錯誤
我的書籤(的index.php)代碼:
<?php
session_start();
//check session first
if (!isset($_SESSION['email'])){
echo "You are not logged in!";
exit();
}
else{
//include the header
include ("../includes/header.php");
require_once ('../../mysql_connect.php');
echo ("<center>");
echo ("<h3>Bookmark</h3><p>");
echo ("<a href=add.php>Add a record</a><p>");
echo ("<a href=searchform.php>Search records</a><p>");
//Set the number of records to display per page
$display = 5;
//Check if the number of required pages has been determined
if(isset($_GET['p'])&&is_numeric($_GET['p'])){//Already been determined
$pages = $_GET['p'];
}
else{//Need to determine
//Count the number of records;
$query = "SELECT COUNT(id) FROM bookmark";
$result = @mysql_query($query);
$row = @mysql_fetch_array($result, MYSQL_NUM);
$records = $row[0]; //get the number of records
//Calculate the number of pages ...
if($records > $display){//More than 1 page is needed
$pages = ceil($records/$display);
}else{
$pages = 1;
}
}// End of p IF.
//Determine where in the database to start returning results ...
if(isset($_GET['s'])&&is_numeric($_GET['s'])){
$start = $_GET['s'];
}else{
$start = 0;
}
//Make the paginated query;
$query = "SELECT * FROM bookmark LIMIT $start, $display";
$result = @mysql_query ($query);
//Table header:
echo "<table cellpadding=5 cellspacing=5 border=1><tr>
<th>Title</th><th>Comment</th><th>URL</th><th>*</th><th>*</th></tr>";
//Fetch and print all the records...
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo "<tr><td>".$row['title']."</td>";
echo "<td>".$row['comment']."</td>";
echo "<td><a href=".$row['url']." target=_blank>".$row['url']."</a></td>";
echo "<td><a href=deleteconfirm.php?id=".$row['id'].">Delete</a></td>";
echo "<td><a href=updateform.php?id=".$row['id'].">Update</a></td></tr>";
} // End of While statement
echo "</table>";
mysql_free_result ($result); // Free up the resources.
mysql_close(); // Close the database connection.
//Make the links to other pages if necessary.
if($pages>1){
echo '<br/><table><tr>';
//Determine what page the script is on:
$current_page = ($start/$display) + 1;
//If it is not the first page, make a Previous button:
if($current_page != 1){
echo '<td><a href="index.php?s='. ($start - $display) . '&p=' . $pages. '"> Previous </a></td>';
}
//Make all the numbered pages:
for($i = 1; $i <= $pages; $i++){
if($i != $current_page){ // if not the current pages, generates links to that page
echo '<td><a href="index.php?s='. (($display*($i-1))). '&p=' . $pages .'"> ' . $i . ' </a></td>';
}else{ // if current page, print the page number
echo '<td>'. $i. '</td>';
}
} //End of FOR loop
//If it is not the last page, make a Next button:
if($current_page != $pages){
echo '<td><a href="index.php?s=' .($start + $display). '&p='. $pages. '"> Next </a></td>';
}
echo '</tr></table>'; //Close the table.
}//End of pages links
//include the footer
include ("../includes/footer.php");
}
?>
對不起格式問題,我還沒有完全想出如何有效地複製和粘貼代碼。
誤區一:
警告:
不管怎麼說,我的問題是由兩個錯誤,我接受,這是派生mysql_fetch_array()預計參數1是資源,布爾在給定的上線50 /home/kethcart/public_html/440/finalproject/htdocs/bookmark/index.php
誤區之二:
警告:了mysql_free_result()預計參數1是資源,在布爾給出/home/kethcart/public_html/440/finalproject/htdocs/bookmark/index.php在線路58
我明白關於這個話題已經有了足夠多的問題,但我似乎無法將它們應用於我的情況。如果有人可以提供關於如何解決這個問題的建議,甚至可以提供關於另一個問題或解決方案的鏈接,那就太棒了!
我很感謝大家的幫助和耐心 - 我不知道沒有這個社區我會做什麼。
感謝,
Rockmandew
大聲笑,所以在試圖壓制錯誤你得到錯誤。我可以問,你只是簡單地嘗試了'mysql_fetch_array(mysql_query($ query),...)'?換句話說,沒有'@' – SpYk3HH
Johannes - 我看到了這個確切的帖子,但是,我繼續問我的問題,因爲我不確定如何將解決方案應用於我的代碼。並不是說我正在尋找某人爲我執行代碼或者說明確的更正,我只是尋找一些關於如何應用更正的指導。謝謝。 – rockmandew
SpYk3HH - 我還沒有嘗試過這種方法,我會暫時測試/應用您的建議,並將結果返回給您。 – rockmandew