请帮帮忙,我贴代码了,现在不用下载文件看了。
a.php 包含一个删除选中书签的复选框<br /><br />function display_user_urls($url_array)<br />{<br /> // display the table of URLs<br /><br /> // set global variable, so we can test later if this is on the page<br /> global $bm_table;<br /> $bm_table = true;<br />?><br /> <br /><br /> <form name='bm_table' action='delete_bms.php' method='post'><br /> <table width=300 cellpadding=2 cellspacing=0><br /> <?php<br /> $color = "#cccccc";<br /> echo "<tr bgcolor='$color'><td><strong>Bookmark</strong></td>";<br /> echo "<td><strong>Delete?</strong></td></tr>";<br /> if (is_array($url_array) && count($url_array)>0)<br /> {<br /> foreach ($url_array as $url)<br /> {<br /> if ($color == "#cccccc")<br /> $color = "#ffffff";<br /> else<br /> $color = "#cccccc";<br /> // remember to call htmlspecialchars() when we are displaying user data<br /> echo "<tr bgcolor='$color'><td><a href=\"$url\">".htmlspecialchars($url)."</a></td>";<br /> echo "<td><input type='checkbox' name=\"del_me[]\"<br /> value=\"$url\"></td>";<br /> echo "</tr>"; <br /> }<br /> }<br /> else<br /> echo "<tr><td>No bookmarks on record</td></tr>";<br />?><br /> </table> <br /> </form><br /><?php<br />}
点击上面删除的复选框后,需要点击下方的删除书签<br /><?php<br /> // only offer the delete option if bookmark table is on this page<br /> global $bm_table;<br /> if($bm_table==true)<br /> echo "<a href='#' onClick='bm_table.submit();'>Delete BM</a> | "; <br /> else<br /> echo "<font color='#cccccc'>Delete BM</font> | "; <br />?>
delete_bms.php 删除函数如下<br /><?php<br /> require_once('bookmark_fns.php');<br /> session_start();<br /> <br /> //create short variable names<br /> $del_me = $HTTP_GET_VARS['del_me'];<br /> $valid_user = $HTTP_GET_VARS['valid_user'];<br /> <br /> do_html_header('Deleting bookmarks');<br /> check_valid_user();<br /> if (!filled_out($HTTP_GET_VARS))<br /> {<br /> echo 'You have not chosen any bookmarks to delete.<br /> Please try again.';<br /> display_user_menu();<br /> do_html_footer(); <br /> exit;<br /> }<br /> else <br /> {<br /> if (count($del_me) >0)<br /> {<br /> foreach($del_me as $url)<br /> {<br /> if (delete_bm($valid_user, $url))<br /> echo 'Deleted '.htmlspecialchars($url).'.<br />';<br /> else<br /> echo 'Could not delete '.htmlspecialchars($url).'.<br />';<br /> } <br /> }<br /> else<br /> echo 'No bookmarks selected for deletion';<br /> }<br /> // get the bookmarks this user has saved<br /> if ($url_array = get_user_urls($valid_user))<br /> display_user_urls($url_array);<br /><br /> display_user_menu(); <br /> do_html_footer();<br />?>
<br>delete_bm函数的代码如下<br><br>function delete_bm($user, $url)<br>{<br> // delete one URL from the database<br> $conn = db_connect(); //此处已经包含在另一个php文件中,连接数据库是正常的<br> // delete the bookmark<br> if (!$conn->query( "delete from bookmark <br> where username='$user' and bm_url='$url'"))<br> throw new Exception('Bookmark could not be deleted');<div class="clear"> </div>