2011-05-31 36 views
0

我需要帮助添加删除状态功能。我需要知道我的删除按钮是否在正确的位置,以及我需要放在我的delete.php页面中的用户评论是否从我的数据库和用户源中删除。需要状态删除功能指导

我听说这很简单。但我无法理解它,这是我从未真正做过的事情。所以我只想让用户按下X和弹出框来链接到delete.php,并且如果被用户删除,它将从流和明显的数据库中删除该注释。

这里是我的STREAMFULL.PHP

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script> 
<script type="text/javascript"> 
               function show_confirm() 
               { 
               var r=confirm("are you sure you want to delete?"); 
               if (r==true) 
                { 
                window.location="http://www.fightstar.org/raw/sn-extend/theme/default/delete.php'"; 
                } 
               else 
                { 
                alert("You pressed Cancel!"); 
                } 
               } 
               </script>' 

<style> 

<?php 


      while($streamitem_data = mysql_fetch_array($chant)){ 
       echo "<div class='stream_object'>"; 
       echo "<table style='word-wrap: break-word;'><td valign='top' style='word-wrap: break-word;padding:5px;'>"; 
       echo "<img class='stream_profileimage' style='border:none;padding:0px;' src='";sn_user_core::output_profile_image_url($streamitem_data['streamitem_creator']);echo "' onerror='this.src=\"sn-admin/css/img/no_profile_img.jpeg\";'><td valign=top>"; 
        $poster_name = sn_user_core::getuser($streamitem_data['streamitem_creator']); 
        $target_name = sn_user_core::getuser($streamitem_data['streamitem_target']); 
        $cont = stripslashes($streamitem_data['streamitem_content']); 

        if(!($streamitem_data['streamitem_type_id']==2)){ 
        $cont = htmlentities($cont); 
        $cont = ereg_replace("[[:alpha:]]+://[^<>[:space:]]+[[:alnum:]/]","<a class='user_link' href=\"\\0\">\\0</a>", $cont); 

        } 

        if($streamitem_data['streamitem_creator']==$streamitem_data['streamitem_target']){ 
         echo "<a href='sn-profile.php?uid=".$poster_name['id']."'>" . $poster_name['firstname']." ".$poster_name['lastname'] ."</a>"; 
        }else{ 
         echo "<a href='sn-profile.php?uid=".$poster_name['id']."'>" .$poster_name['firstname']." ".$poster_name['lastname'] ." </a> 
         > 
           <a href='sn-profile.php?uid=".$target_name['id']."'>" .$target_name['firstname']." ".$target_name['lastname'] ."</a>"; 
        } 

        if($streamitem_data['streamitem_type_id']==2){ 
        $cont = nl2br($cont); 
        echo "<div style='display:inline;'> ".$cont." </div>"; 
        }else{ 

         if($streamitem_data['streamitem_creator']==$streamitem_data['streamitem_target']){ 
         $cont = nl2br($cont); 
          echo "<div>".$cont."</div>"; 
         }else{ 
         $cont = nl2br($cont); 
         echo "<div>".$cont."</div>"; 
         } 

        } 
       echo "<div class='post_contextoptions'>"; 

           echo "<div class='stream_option'>".Agotime($streamitem_data['streamitem_timestamp']); 
            if(!($streamitem_data['streamitem_viaid']==0)){ 


        //COMMENTS 

         echo '<a href="" onclick="show_confirm()" alt="Delete" title="Delete" class="delete">X</a>&nbsp;&nbsp;&nbsp;&nbsp;'; 
      } 

回答

1

现在你的脚本不能做任何事情,而是将用户重定向到一个'delete.php页面,如果他们打确认。您需要嵌入某种标识符以显示他们点击删除按钮的评论。这会使url看起来像http://example.com/delete.php?commentID=123。删除脚本将检索评论ID并执行任何操作。

这就是我要去的地方。我不会通读你的代码墙来找出你想要做的事情。虽然显示代码总是受欢迎,但这太方便了。将它简单归纳为你想要做的一个代表性样本。我们希望悬崖的笔记版本,而不是完整的和平战争&和平。

+0

Ok Marc。但是,如果我只是添加commentID = 123,它不会只删除评论123,不会说用户点击122的评论。我会删除现在不相关的部分。 – 2011-05-31 22:07:58

+0

好的,我已经完成了一个编辑,并将其剪下来,只留下javascript的注释 – 2011-05-31 22:11:37

+0

嗯,你会动态地填写评论ID。 123只是一个例子。 – 2011-05-31 22:15:26

0

这有什么困难吗?

开始Situtation:你在数据库评论

下一页:

  1. 用户识别
  2. 用户浏览到一个显示我的评论页面
  3. 显示我的评论页面是displaye,例如具有可点击并且已经与主键绑定的评论预览的列表,例如:

    A HREF = SomePage的?comm_id = $ RES [0]> SUBSTR($ RES [1],0,50)/一个

其中$解析度是与从MySQL 0的结果和$ RES [阵列]是主键的值,$ res [1]是注释的预览。评论点击 4.之后你仍然有它的ID,所以,在新的页面编辑显示此评论,删除任何这样的按钮:

<form .... action=delete.php> 
<input type=button name=edit value=edit> 
<input type=button name=delete value=delete> 
<input type=hidden name=comment_id value=$_GET['comm_id']> 
</form> 

其中$ _GET [comm_id]从以前来到页。

在这一点上,你可以选择去传统方式或HTTP请求来调用delete.php

  1. 一旦你有了delete.php活着它是这样:

    如果(isset( $ _POST ['delete'])) delete($ _ POST ['comment_id']) ...等

和删除功能仅仅是这样:

...etc 
$sql='delet...etc where `id`='.$_POST['comment_id'] 
...etc 

上成功展示失败一些其他的一些网页...

当然没有安全,SQL注入攻击没有给出在这里,这是你的工作..这只是一个基本的场景。

你总是希望尽可能使自动化,数据清理,sql插入,查询等都成为实现事物自动化的完美基础!

+0

好吧,梅尔西,你让我更接近,我点击删除按钮,它显示浏览器中的ID。 这是删除按钮 echo'X        '; 而结果 mysite/raw/sn-extend/theme/default/delete.php?= 1503 但是,当它导航到delete.php它说未发现评论,所以也许我现在在delet.php页面有错误。 – 2011-05-31 23:41:27

+0

在这种情况下,你总是会分裂和隔离事物。调试场景示例: – Melsi 2011-06-01 07:24:18

0

不要在您的网站:

1.Echo the sql in the page(just for testing) 
2.Copy the id 

不要在mysql客户,你知道所有的以下(heidisql是免费的)

2.Paste sql to the sql editor,click the execute button (is a blue one) 
5.after you make the sql working 100% check results 
6.1 A result is returned then ok leave the client 
6.2 A result is not returned you can view the data of the table (click data tab) copy an existing value paste it to the sql editor and now the query must return this record 

这种方式,你应该集中或那里的问题是: - 查询 - 错误的编号 等

通常经常需要echo sql并直接运行它当仍然在发展时,从客户那里获得。成功的调试通常需要单独进行隔离和测试。在PHP的debuggin最常见的,简单的工具的组合:

print_r [you see the structure of sth] 
var_dump [in addition show type of, int, str etc] 
echo [if hello is echoed this means the code reaches at certain point] 
if(true){echo 'hello';} [if hello is echoed then the condition inside if was the problem] 
echo 'hello'; exit; [you don't care for the rest you want to check up to hello] 
die('hello') [fast way for echo 'string';exit; die does not work well with int die(332)] 

注意:需要几个基本sequrity措施。 1.任何登录的用户都可以在更改url上的id时删除其他人的评论,以便在删除评论之前确保至少要删除的评论与登录的用户相匹配,例如伪代码: 如果存在行其中评论id =登录用户ID返回true否则返回false 如果为true删除如果为false不删除 2.尽可能使用PDO方式,如果使用得当,可以帮助进行sql注入攻击。 3.可以使用后可能insted得到,如果你搜索关于php安全有很多可用。 Ok Marc。