简体   繁体   English

PHP MySQL身份验证问题

[英]php mysql authentication problems

I was adding a delete function to my mysql database database but when i hit the submit button i get this Error message "DELETE command denied to user ''@'localhost' for table 'people" Ive taken a look at the user root to see and it has all priveleges added please help this is the code im working on 我在我的mysql数据库数据库中添加了删除功能,但是当我按下“提交”按钮时,我收到此错误消息“对表'people'的用户'@'localhost'拒绝了DELETE命令”我看了一下用户root来查看并且它添加了所有特权,请帮助,这是我正在处理的代码

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "yoga";

$conn = new mysqli($servername, $username, $password, $dbname);

    if($conn -> connect_error){
        die("connection failed: ".$conn -> connect_error);
    }

        if(isset($_POST['delete'])){


        mysql_query("DELETE FROM `yoga`.`people` WHERE `people`.`id` =          '$_POST[deleteId]' ") or die(mysql_error());
        }

    ?>

Wonder your username is null as per the error message, which means username value is not passed 想知道您的用户名是否为空 (根据错误消息),这意味着未传递用户名值

"DELETE command denied to user ''@'localhost' for table 'people" “对表'people'的用户'@'localhost'的DELETE命令被拒绝”


If it is due to insufficient privileges. 如果是由于特权不足。 Check the result of 检查结果

SHOW GRANTS FOR 'root'@'localhost';

Ensure you have the right privileges 确保您拥有正确的特权

GRANT DELETE ON `yoga`.`people` TO 'root'@'localhost';
or
GRANT DELETE ON `yoga`.* TO 'root'@'localhost';
FLUSH PRIVILEGES;

Also sometimes it is found that the queries which works in phpmyadmin may not work in server . 也有时发现在phpmyadmin中有效查询可能在服务器中不起作用 To make that work in any platform, try this instead (omitting the database name) 要使其在任何平台上都能正常工作,请尝试使用此方法(省略数据库名称)

schema_name.table_name to table_name schema_name.table_nametable_name

DELETE FROM people WHERE `people`.`id` = '$_POST[deleteId]' "

You don't use the connection you have created. 您不使用已创建的连接。 Change the query line to this: 将查询行更改为此:

 $conn->query("DELETE FROM `yoga`.`people` WHERE `people`.`id` =          '$_POST[deleteId]' ") or die($conn->error);

I would also recommend that you use prepared statements, because now you are vulnerable to sql injection. 我还建议您使用准备好的语句,因为现在您容易受到sql注入的攻击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM