>  기사  >  백엔드 개발  >  请帮帮忙,小弟我贴代码了,现在不用下载文件看了

请帮帮忙,小弟我贴代码了,现在不用下载文件看了

WBOY
WBOY원래의
2016-06-13 11:58:37984검색

请帮帮忙,我贴代码了,现在不用下载文件看了。

本帖最后由 abkey1 于 2014-06-01 10:13:30 编辑
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>
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.