我有一个表单,可以将用户添加到 mysql 数据库表中,并将新信息通过电子邮件发送到某个地址(工作)。
现在我有一个用于从表中删除记录的表单,但我无法让它在删除之前通过电子邮件发送旧用户数据。
例如,如果用户从表中删除 id 45,则必须发送一封电子邮件,说明“用户已从表中删除:‘姓名’、‘电话’、‘分机号’”
delete.php 代码:
<?php
require ("database.php");
?>
<?php
$this_Stud_ID =$_REQUEST['id'];
// sending query
mysql_query("DELETE FROM users WHERE id = '$this_Stud_ID'")
or die(mysql_error());
if($_POST['action'])
header("Location: index.php");
?>
<form action="<?php echo $_SERVER['php_self'] ?>" method="post">
Enter ID Number :<br><input type="text" name="id"><br />
<br><input type="submit" name="action" value="Delete!">
<br> <br>
<h3>
<a href="index.php"> Main Menu </a>
</h3>
</form>
最佳答案
您必须在删除之前获取用户数据。 做这样的事情
<?php
require ("database.php");
if(isset($_POST['action'])){
if(isset($_REQUEST['id']) && (int)$_REQUEST['id']>0){
$this_Stud_ID =(int)$_REQUEST['id'];
$user_record=mysql_fetch_assoc(mysql_query('select * from users where id=' . $this_Stud_ID));
//now send an email to user or to anyone and use $user_record as user data
$to='';
$subject='';
$message='';
$headers='';
$mail_status=mail($to, $subject, $message, $headers);
if($mail_status){
mysql_query("DELETE FROM users WHERE id = '$this_Stud_ID'")or die(mysql_error());
header("Location: index.php");
exit();
}
}
}
?>
<form action="<?php echo $_SERVER['php_self'] ?>" method="post">
Enter ID Number :<br><input type="text" name="id"><br />
<br><input type="submit" name="action" value="Delete!">
<br> <br>
<h3><a href="index.php"> Main Menu </a></h3>
</form>
关于php - 发送 phpmailer 删除数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41972903/