我需要一些MySQL数据库的帮助。我需要有一个功能,用户可以通过输入电子邮件地址从数据库中删除自己,然后它会询问他们是否100%确定他们想要删除自己然后它将从数据库中删除它们。任何帮助将不胜感激!
以下是显示数据库中当前用户的页面 - http://www.ironicwhiplash.com/join/members.php
编辑我不是说我想让别人为我编写代码!很抱歉,如果它遇到这种方式,因为它是在清晨,我试图明天完成,因为我说它会完成!感谢Joao的非常有帮助的答案!
编辑2 我已经使用Joao上述帖子的代码制作了代码。下面是它使用的最终代码:)希望它可以帮助某人。
我使用了一个用户输入电子邮件地址的页面:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Leave</title>
</head>
<body>
<form action="remove.php" method="post">
<label style="color:#000">Email:</label><br/>
<input name="email" type="email" required="required" style="color:#000"> <br/>
<input type="submit" value="Leave" class="btn btn-danger">
</form>
</body>
</html>
然后我有另一个名为'remove.php'的文件:
<?php
$host="localhost"; // Host name
$username="username"; // Mysql username
$password="password"; // Mysql password
$db_name="database name"; // Database name
$tbl_name="tablename"; // Table name
// Connect to server.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$email=$_POST['email']; //Fetch the email address from the last page and set it as a variable called '$ email'
$sql="DELETE FROM $tbl_name
WHERE email='$email'"; //Delete the user where the email address is the same as the one which they put in the last form
$result=mysql_query($sql); //Find the result of the executed code
if($result){
echo "Successfully Removed"; //Tell the user if it was removed successfully
}
else {
echo "ERROR"; //Tell you if there is a error.
}
mysql_close(); //Close your SQL connection
?>
查理:)