我想在用戶提交正確的密碼後顯示一條消息,通知用戶他已被刪除,從而刪除用戶。檢查密碼正確後刪除用戶
在我的代碼中,問題是無論用戶如何寫入系統,都要考慮寫入並允許刪除。
刪除.PHP
<?php
session_start();
$msgToUser="";
if(@!$_SESSION['user_id'])
{
$msgToUser= '<br /><br /><font color = "#FF000">Only registered users can delete their account</font><p><a href = "register.php">Join Here</a></p>';
exit();
}
$id = $_SESSION['user_id'];
if(isset($_POST['delete']))
{
$del_acct_pass = $_POST['del_account_pass'];
require_once('include/connect.php');
$check_pass= mysql_query("SELECT password FROM user WHERE password = '$del_acct_pass' AND user_id = '$id'") or die(mysql_error());
if($check_pass)
{
$sql = mysql_query("SELECT * FROM user WHERE user_id = '$id'")or die(mysql_error());
$pass_check_num = mysql_num_rows($sql);
if($pass_check_num >0)
{
$pic1=("members/$id/image01.jpg");
if(file_exists($pic1))
{
unlink($pic1);
}
$dir = "members/$id";
rmdir($dir);
$sqltable1 = mysql_query("DELETE FROM user WHERE user_id ='$id'")or die(mysql_error());
$sqltable1 = mysql_query("DELETE FROM blabing WHERE u_id ='$id'")or die(mysql_error());
session_destroy();
$msgToUser="YOUR Account Has Been Deleted!!!";
exit();
}
}
$msgToUser="<h3 style='color:#CC0000'>You must Write the Correct Password</h3>";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Edit Page</title>
<link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css' />
<link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css' />
<link href="default.css" rel="stylesheet" type="text/css" media="all" />
</head>
<body>
<?php /*require_once('header.php');*/ ?>
<div id="wrapper">
<div id="page-wrapper">
<div id="page">
<div id="wide-content">
<table width="70%" align="center" cellpadding="6">
<form action="delete_account.php" method="post" name="delete_form" >
<tr>
<td bgcolor="#CCCCCC">Delete Your Account </td>
</tr>
<tr>
<td>Please enter Your current Password to proceed with account deletion</td>
</tr>
<tr>
<td><input type="password" name="del_account_pass" id="del_account_pass" /></td>
</tr>
<tr>
<td><input type="submit" name="delete" id="delete" value="Delete Account" /></td>
</tr>
<tr>
<td><?php echo $msgToUser; ?></td>
</tr>
</form>
</table>
</div>
</div>
</div>
</div>
<?php require_once('footer.php'); ?>
</body>
</html>
你的第二句話沒有意義,請澄清。 – 2013-05-12 08:35:00
請注意,您的代碼容易受到[SQL注入](http://en.wikipedia.org/wiki/SQL_injection)的影響。你應該確保你正確地逃避用戶輸入。在這種情況下'$ del_acct_pass'和可能'user_id',取決於如何生成。 – Steve 2013-05-12 08:36:35