Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从数据库中删除用户_Php_Sql_Phpmyadmin - Fatal编程技术网

Php 从数据库中删除用户

Php 从数据库中删除用户,php,sql,phpmyadmin,Php,Sql,Phpmyadmin,当我从数据库中删除一个用户时,我不断收到一条错误消息,提示此时无法删除该用户帐户。我找不到任何突出的sytanx错误,我非常确定我的sql查询是正确的。删除用户帐户的表单要求输入用户名、密码、名字和电子邮件,但只检查用户名和密码。我走错方向了吗 <!-- To change this template, choose Tools | Templates and open the template in the editor. --> <!DOCTYPE html> <

当我从数据库中删除一个用户时,我不断收到一条错误消息,提示此时无法删除该用户帐户。我找不到任何突出的sytanx错误,我非常确定我的sql查询是正确的。删除用户帐户的表单要求输入用户名、密码、名字和电子邮件,但只检查用户名和密码。我走错方向了吗

<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Deleting Account </title>
    </head>
    <body>
        <?php
                  $db_server = "server";
                  $db_username = "name";
                  $db_password = "pass";

       $con = mysql_connect($db_server, $db_username, $db_password);if (!$con)
                {
                    die('Could not connect: ' . mysql_error());
                }

               $database = "Account_Holder";  

              $er = mysql_select_db($db_username);
        if (!$er) 
        {
         print ("Error - Could not select the database");
         exit;
        }        
            if (isset($_POST['Submit']) && isset($_POST['firstname']) && isset($_POST['password']) && isset($_POST['username'])&& isset($_P0ST['email']))
            {

            //if (isset($_POST['Submit'])
            //{
            $firstname =  $_P0ST['firstname']; 
            $password =  $_POST['password']; 
            $username =  $_P0ST['username']; 
            $email = $_P0ST['email'];

                $query = "DELETE FROM Account_Holder WHERE username ='$username' AND password ='$password'";
                $result = mysql_query($query);
                print("Your account has been deleted. Goodbye."); 
            }
            else
            {
                print("Your account can not be deleted at this time."); 
            }
        ?>
    </body>
</html>

删除帐户

查询的数据库名为“Account\u Holder”,而不是表名

$query = "DELETE FROM Account_Holder WHERE username ='$username' AND password ='$password'";

将其更改为适当的表名,然后重试。

在我看来,
if
语句中的某些内容未按预期设置:

其中一项未在帖子中设置:提交、名字、密码、用户名或电子邮件

我会检查你的表单,确保它的method属性设置为“post”,并且你的表单中有与之匹配的元素。您还可以在web调试器(如Fiddler、Firebug或Dragonfly)中打开它,让您看到发布的请求,并且您可以确保所有这些元素都实际发送到服务器
和check是该
语句中的所有值

 if (isset($_POST['Submit']) && isset($_POST['firstname']) && isset($_POST['password']) && isset($_POST['username'])&& isset($_P0ST['email']))
我知道你在代码中做了验证
只要你检查一下就行了


或者,表的名称与数据库的名称相同。无论哪种方式,这都与此无关,因为它不是导致程序逻辑执行“account can can can can Delete”(帐户不能删除)文本的SQL异常。它不在if语句中,因此我认为queryPlease中没有问题。请提供提交到此页的表单的HTML,并确认您问题中的当前代码与源代码中的代码完全相同[您最长的行
isset($\u POST['username'])和&isset($\u P0ST['email'])
应该是
isset($\u POST['username'])和&isset($\u POST['email'])
变量区分大小写。我认为这意味着数组键也区分大小写。如果Submit是Submit,则它可能不是isset。我们也可以打印($\u POST)。
if (isset($_POST['Submit'])) {

   $firstname =  $_POST['firstname']; 
   $password =  $_POST['password']; 
   $username =  $_POST['username']; 
   $email = $_POST['email'];

   $query = "DELETE FROM Account_Holder WHERE username ='$username' AND password ='$password'";
         $result = mysql_query($query);
         print("Your account has been deleted. Goodbye."); 
} else {
     print("error..");
}