duanchen1937 2015-08-14 14:41 采纳率: 0%
浏览 32
已采纳

$ _GET停止了删除记录的工作

For a webapplication I'm building the delete user function stopped working. I didn't change anything related to this function. So I'm quite puzzeled. I have PHP Console installed in chrome (and the app). But it isn't giving any errors or warnings.

I'm using bootbox to verify if the user really should be deleted:

function delete_id(id, fullname) {
    bootbox.confirm({
        size: 'small',
        message: '<i class="glyphicon glyphicon-question-sign orange"></i>Are you sure you want to delete user "'+fullname+'"?',
        callback: function(result) {
            if(result) {
                window.location.href = '?delete_id='+id;
            } 
        }
    });
}

Then it should be passed through my php function:

function delete_user ($mysqli) {
    if(isset($_GET['delete_id'])) {
        $sql_name = "SELECT * FROM users WHERE uid='".$_GET['delete_id']."'";
        $result_name = $mysqli->query($sql_name);
        $row = $result_name->fetch_assoc();

        $sql_log = "DELETE FROM loginlog WHERE uid='".$row['uid']."'";
        $result_log = $mysqli->query($sql_log);

        $sql_user = "DELETE FROM users WHERE uid='".$row['uid']."'";
        $result_user = $mysqli->query($sql_user) or die(mysqli_errno($mysqli));

        $_SESSION['success'] = "User \"".$row['firstname']." ".$row['prefix']." ".$row['lastname']."\" is deleted.";
        header("location: ".BASE_PATH."/includes/views/users.php");
        exit();
    }
}

the delete_user() function is called in users.php And this was working just fine, but now it isn't anymore.. Am I overlooking something?

  • 写回答

1条回答 默认 最新

  • douzhi6160 2015-08-14 15:54
    关注

    I would advise:

    function delete_user ($mysqli, $id) {
        if(isset($id)) {
            $sql_name = sprintf("SELECT * FROM users WHERE uid='%d'", $id);
            $result_name = $mysqli->query($sql_name);
            $row = $result_name->fetch_assoc();
    
            $sql_log = "DELETE FROM loginlog WHERE uid='{$row['uid']}'";
            $result_log = $mysqli->query($sql_log);
    
            $sql_user = "DELETE FROM users WHERE uid='{$row['uid']}'";
            $result_user = $mysqli->query($sql_user) or die(mysqli_errno($mysqli));
    
            $_SESSION['success'] = "User \"{$row['firstname']} {$row['prefix']} {$row['lastname']}\" is deleted.";
            return true;
        } else {
            return false;
        }
    }
    

    Then you can execute:

    if(delete_user($sql, $_GET['id'])){
        header("location: ".BASE_PATH."/includes/views/users.php");
    }
    

    It's always good to use best practices, even in a intranet. One rouge user or someone that thinks they know a little something, and you could lose tables or have rows fowled. ALWAYS protect your user entered data, especially from the users.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改