需求状态删除功能指南

| 我需要添加删除状态功能的帮助。我需要知道我的删除按钮是否在正确的位置,以及我需要在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;\';
            }
    
已邀请:
        现在,您的脚本不会执行任何操作,但是如果用户单击确认,则将用户重定向到\'delete.php \'页面。您需要嵌入某种标识符,以显示他们单击了删除按钮的注释。这会使网址看起来像“ 1”。删除脚本将检索注释ID并执行任何操作。 就我所能达到的程度。我不会通读代码墙以弄清楚您要做什么。虽然总是欢迎显示代码,但实在太多了。将其提炼为您要尝试的代表性示例。我们需要Cliff \'s Notes版本,而不是完整的《战争与和平》。     
        这有什么难的? 开始情况:您在数据库中有一条评论 下一个: 用户识别 用户浏览到显示我的评论页面 显示“显示我的评论”页面,例如带有评论预览的列表,该列表是可单击的并且已经与主键绑定,例如: a href = somepage?comm_id = $ res [0]> substr($ res [1],0,50)/ a 其中$ 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 一旦您拥有delete.php,它就会变成: if(isset($ _ POST [\'delete \']))    删除($ _POST [\'comment_id \']) ...等等 删除功能就像:
...etc
$sql=\'delet...etc where `id`=\'.$_POST[\'comment_id\']
...etc 
成功时显示一些失败时页面... 当然没有安全性,这里没有给出sql攻击预防,这是您的工作。这只是一个基本情况。 您始终希望使事情尽可能地自动化,数据清理,SQL插入,查询等都为自动化事情提供了理想的基础!     
        在您的网站上执行以下操作:
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
通过这种方式,您可以知道应该关注的地方或问题所在: -查询 -错误的ID 等等 通常,当仍在开发中时,通常需要回显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的同时删除某人的其他注释,因此在删除注释之前,请确保至少要删除的注释与登录的用户匹配,例如伪代码: 如果存在行,其中注释id =登录用户ID,则返回true,否则返回false 如果为true,则删除;如果为false,则不删除 2.尽可能采用PDO方式,如果使用得当,可以帮助进行sql注入攻击。 3.可以在可能的情况下使用post,如果您搜索有关php安全的信息,则有很多可用的方法。     

要回复问题请先登录注册