当我从数据库中删除用户时,我不断收到错误消息,表示目前无法删除用户帐户。我找不到任何突出的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>
答案 0 :(得分:0)
您的查询的数据库名称为“Account_Holder”而不是表名。
$query = "DELETE FROM Account_Holder WHERE username ='$username' AND password ='$password'";
将其更改为适当的表名,然后重试。
答案 1 :(得分:0)
在我看来,if
语句中的某些内容未按预期设置:
其中一个未在POST中设置:提交,名字,密码,用户名或电子邮件
我会检查您的表单以确保它将方法属性设置为“post”,并且您的表单中包含与之匹配的元素。您也可以在Fiddler,Firebug或Dragonfly等Web调试器中打开它,以便查看POSTed请求,并确保所有这些元素实际上都被发送到服务器。
答案 2 :(得分:0)
print_r($_POST);
并检查此if
语句中的所有值是否来临
if (isset($_POST['Submit']) && isset($_POST['firstname']) && isset($_POST['password']) && isset($_POST['username'])&& isset($_P0ST['email']))
答案 3 :(得分:-1)
我假设您在代码中完成了验证,只需要检查
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..");
}