我想把数据库的记录1条1条的删除..做了1个前台页面1个后台..请帮我看看有什么问题..

我想把数据库的记录1条1条的删除..做了1个前台页面1个后台..请帮我看看有什么问题..

-------后台
  function del_entry()
  {
    global $name, $email, $url, $message, $posted, $ip, $table;
    connect_db();
    $del=mysql_query("delete from $table where id=$id");
    $result = mysql_db_query(edm,$del);
    echo "$result";



  }
--------前台------------
<html>

<head>
  <title></title>
</head>

<body>

<form name="del_form" action="del.php" method="post">
  <?php
      require ("vars.inc.php");
      @mysql_connect($db_host, $db_user, $db_pass);
      @mysql_select_db($db_name)  or die ("Unable to connect to database");
      ?>
  <?php
        $result=mysql_query("select * from $table");
        while($rs=mysql_fetch_array($result)){
        ?>
           <input name="id[]" type="checkbox" id="id[]" value="<?=$rs[id]?>" />
        <?=$rs[id]?>   <br>
        <?php
        }
     ?>
     <input type=submit value=确定删除>
   </form>

</body>

</html>

有什么问题?你这么说谁知道?有问题没有提示的吗
如履薄冰

我这里 echo "$result";

想把结果打出来看..结果没打出来也不知道为什么..我刚学不好意思呀

好象delete  sql语句没有 执行

我把请求id 发送到后台的哪个id 上..然后后台执行sql 把数据删掉

我写的好象id 没有传到后台,但是我不知道怎么改了

[ 本帖最后由 如海一生 于 2006-10-19 16:48 编辑 ]

改成这个看看<?=$rs['id']?>
你一个配置它提示错误
如履薄冰

我把全部的都贴上来大家看看啊
vars.inc.php

<?
  /*
     filename = vars.inc.php scriptname = AWSMySQLguest: edit the following as needed
     all functions for the guestbook are in this file
  */

  $home_url = 'http://www.edm.com'; // url of your website
  $bgcolor = '#000000';
  $title = 'MySQL Guestbook Demo'; //title of your site
  $font = 'Verdana';
  $fontcolor = '#FFFFFF';
  $tfont = '#FF0000';
  $guestinfo_tcolor = '#C0C0C0';
  $messagebody_tablecolor = '#CCCCCC';
  $guestinfo_fontcolor = '#800000';
  $messagebody_fontcolor = '#CC2800';
  $posted = Date("M d, Y");
  $ok_to_post = 1;
  $error_string = '<font color=\"#00FF00\"><b><i>Hit your browsers back button and resubmit the form.</b></i>';
  $db_host = '192.168.1.34';
  $db_name = 'edm';  //change to your database name
  $db_user = 'edm';      //change to your username for the db
  $db_pass = '';    //change to your db password
  $table = 'guest';       //change to your table name if needed. if you change this you must also change the name in awsguest.sql file
  $ip = getenv('REMOTE_ADDR');

  define ("n", "<br>\n");

  /*
     you can change the html in the 3 functions below to fit your needs. Make sure
     you don't remove the " at the begining and end of the html block. Do not
     remove the link to Allwebscripts in the finish_page function.
  */

  function start_page(){
      global $title, $bgcolor, $fontcolor, $homeurl, $font;
      echo "
            <html>
            <head>
            <title>$title</title>
            </head>
            <body bgcolor=\"$bgcolor\" text=\"$fontcolor\">
            <center><h1>$title</h1></center>
            <a href=\"$home_url\"><b>Home</a><br><a href=\"$home_url/view.php\">View our Guestbook</a></b>
            <br>
            <br>
          ";
  }

   function start_page2(){
      global $title, $bgcolor, $fontcolor, $homeurl, $font, $tfont, $guestinfo_fontcolor, $messagebody_tablecolor, $guestinfo_tcolor;
      echo "
          <html>
          <head>
          <title>$title</title>
          </head>
          <body bgcolor=\"$bgcolor\" text=\"$fontcolor\">
          <center><h1>$title</h1></center>
          <a href=\"$home_url\"><b>Home</a><br><a href=\"$home_url/AWSguest.php\">Sign our Guestbook</a></b>
      ";
  }

  function finish_page(){
      echo "
          <br>
          <br>
          <br>
          <center><font size=\"-1\" color=\"#CCCCCC\">ts <a href=\"http://www.do-start.com\">teamsourcing</a></font></center>
          </body>
          </html>
      ";
  }

  /* nothing needs to be changed below this line */

  function connect_db(){
      global $db_host, $db_name, $db_user, $db_pass;
      @mysql_connect($db_host, $db_user, $db_pass);
      @mysql_select_db($db_name)  or die ("Unable to connect to database");
  }

  function add_entry(){
       global $name, $email, $url, $message, $posted, $ip, $table;
       echo ("".n.n.n);
       $entered = FALSE;
       $add = "INSERT INTO $table ( name, email, url, message, posted, ip) VALUES ('$name', '$email', '$url', '$message', '$posted', '$ip')";
       connect_db();
       $added = mysql_query($add) or die("Could not add entry".n);
       if (!$added) {
           echo ("Error: Could not add entry".n);
           $entered = FALSE;
           exit;
       }
       else {
           $entered = TRUE;
           echo ("<h2>Thank you for signing our guestbook</h2>".n.n.n);
           echo ("Entered into guestbook:".n);
           echo ("Name : $name".n);
           echo ("Email : $email".n);
           echo ("Homepage : $url".n);
           echo ("Message : $message".n);
           echo ("Posted On : $posted".n);
           echo ("IP : $ip".n.n.n.n.n);
            echo ("12211212>");
      }
  }

   function get_entry(){
        global $name, $email, $url, $message, $posted, $ip, $table, $tfont, $guestinfo_fontcolor, $messagebody_tablecolor, $guestinfo_tcolor;
        echo ("".n.n.n);
        connect_db();
        $view = "SELECT id, name, email, url, message, posted, ip FROM $table ORDER BY id DESC";
        $list = mysql_query($view) or die("Could not get data".n);
        while ($all = mysql_fetch_array($list))
        {
            extract($all);
            echo "<br><div align=\"center\">";
            echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"85%\">";
            echo "<td width=\"10%\" bgcolor=\"$guestinfo_tcolor\" align=\"left\" valign=\"top\">";
            echo "<p align=\"left\"><font color=\"$tfont\"><b>Last Signed: </b></font><br>";
            echo "<b><font color=\"$tfont\">ID:</font></b><br>";
            echo "<b><font color=\"$tfont\">By:</font></b><br>";
            echo "<font color=\"$tfont\"><b>E-Mail:<br>Homepage:</b></font><br>";
            echo "<font color=\"$tfont\"><b>IP:</b></font></td>";
            echo "<td width=\"50%\" bgcolor=\"$guestinfo_tcolor\" valign=\"top\">";
            echo "<font color=\"$guestinfo_fontcolor\">$posted<br>$id<br>$name<br>$email<br><a href=\"$url\">$url</a><br>$ip</td></tr></table></div>";
            echo "<div align=\"center\">";
            echo "<table border=\"0\" cellpadding=\"0\" cellspacing=\"2\" width=\"85%\">";
            echo "<tr>";
            echo "<td width=\"13%\" bgcolor=\"$messagebody_tablecolor\" valign=\"top\" align=\"left\"><font color=\"$tfont\"><b>Message:</b></font></td>";
            echo "<td width=\"65%\" valign=\"top\" bgcolor=\"$messagebody_tablecolor\">$message</td></tr></table></div>";
            echo "<hr>";
          }
           mysql_free_result($list);
   }


  function del_entry()
  {
    global $name, $email, $url, $message, $posted, $ip, $table;
    connect_db();
    $del=mysql_query("delete from $table where id=<?=$rs[id]?>");
       echo "$del";
    $result = mysql_db_query(edm,$del);
    echo "$del";

  }

?>

---------del.php
<?
   /* filename = view.php scriptname = AWSMySQL Guest */

   Require ("vars.inc.php");

   start_page2();
      ?>


   <?
   del_entry();
   ?>

<?
   finish_page();

?>
-------------------testdel.php
<html>

<head>
  <title></title>
</head>

<body>

<form name="del_form" action="del.php" method="post">
  <?php
      require ("vars.inc.php");
      @mysql_connect($db_host, $db_user, $db_pass);
      @mysql_select_db($db_name)  or die ("Unable to connect to database");
      ?>
  <?php
        $result=mysql_query("select * from $table");
        while($rs=mysql_fetch_array($result)){
        ?>
           <input name="id[]" type="checkbox" id="id[]" value="<?=$rs[id]?>" />
        <?=$rs[id]?>   <br>
        <?php
        }
     ?>
     <input type=submit value=确定删除>
   </form>

</body>

</html>

着就是我用到的代码了..我想写这个删除的功能但是就是不能删除数据不知道为什么啊

[ 本帖最后由 如海一生 于 2006-10-19 16:59 编辑 ]

测试干吗要那么多代码阿,写个简简单单的,看看能不能删除,也容易找到错误阿
如履薄冰

麻烦帮我看看了..其实也不多啦 几个函数我写的很明确了..

就最后一个删除的那个有问题...

del .php 处理sql页
-----------------------------------
<?php
   /* filename = view.php scriptname = AWSMySQL Guest */

   Require ("vars.inc.php");
   connect_db();
   $del=mysql_query("delete from $table where id=3");
   $result = mysql_db_query(edm,$del);
   echo "$result";

   ?>

--------------------------------------------------------------------------------
..............前台页
testdel.php
--------------
<html>

<head>
  <title></title>
</head>

<body>

<form name="del_form" action="del.php" method="post">
  <?php
      require ("vars.inc.php");
      @mysql_connect($db_host, $db_user, $db_pass);
      @mysql_select_db($db_name)  or die ("Unable to connect to database");
      ?>
  <?php
        $result=mysql_query("select * from $table");
        while($rs=mysql_fetch_array($result)){
        ?>
           <input name="id[]" type="checkbox" id="id[]" value="<?=$rs[id]?>" />
        <?=$rs[id]?><br>
        <?php
        }
     ?>
     <input type=submit value=确定删除>
   </form>

</body>

</html>
这样是我精简过了..麻烦高手帮忙给解决下问题

$result = mysql_db_query(edm,$del);
edm 是什么?
毕业了。。。

edm 是我的数据库呀

$del=mysql_query("delete from $table where id=3");

3 这个位置的id 我想从前台页面 传到这个位置,我直接写这个id 可以删除,但是如何把 前台的传到后面呢?

[ 本帖最后由 如海一生 于 2006-10-20 09:03 编辑 ]