需要状态删除功能指南

时间:2011-05-31 21:44:27

标签: php social-networking status

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

我听说这很简单。但我无法理解它,这是我从未真正做过的事情。所以我只想让用户按下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;';
            }

3 个答案:

答案 0 :(得分:1)

现在,如果用户点击确认,您的脚本不会执行任何操作,只会将用户重定向到“delete.php”页面。您需要嵌入某种标识符来显示他们点击删除按钮的注释。这会使网址看起来像http://example.com/delete.php?commentID=123。删除脚本将检索注释ID并执行任何操作。

这就是我要去的地方。我不打算阅读你的代码墙来弄清楚你想要做什么。虽然显示代码总是受欢迎的,但这太过分了。将其提取到您要尝试的代表性样本。我们想要Cliff's Notes版本,而不是完整的War&amp;和平。

答案 1 :(得分:0)

它有什么困难?

启动Situtation:您在数据库中有评论

下一步:

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

    a href = somepage?comm_id = $ res [0]&gt; substr($ res [1],0,50)/ a

  4. 其中$ res是一个包含mysql结果的数组,$ res [0]是主键的值,$ 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 [ '删除']))    删除($ _ POST [ 'COMMENT_ID']) ...等

    2. ,删除功能就像:

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

      成功显示一些失败的页面......

      当然没有安全性,这里没有给出sql攻击预防,这是你的工作......这只是一个基本场景。

      你总是想让事情尽可能地自动化,数据清理,sql插入,查询等都是自动化事物的完美基础!

答案 2 :(得分: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

通过这种方式,您可以知道应该关注的位置或问题所在: - 查询 - 错误的身份证 等

一般来说,经常需要回显sql并在开发时直接从客户端运行它。成功的调试通常需要单独隔离和测试事物。在php中,用于调试的最常见的简单工具是:

的组合
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)]

注意:采取一些基本的基本措施。 1.任何登录用户都可以在更改URL上的id时删除某人的其他注释,因此在删除注释之前,请确保至少要删除的注释与登录用户匹配,例如伪代码: 如果行存在,其中comment id =登录用户id返回true,否则返回false 如果为true则删除如果为false则不删除 2.尽可能采用PDO方式,如果使用得当,可以帮助进行sql注入攻击。 3.可以在可能的情况下使用post获取,如果你搜索php安全性有很多可用。