dshun123456 2017-02-01 06:00
浏览 93
已采纳

发送phpmailer数据删除

I have a form that adds a user to a mysql database table and emails the new information to a address (working).

Now I have a form that is used to delete records from the table but I am unable to get it to email the old users data before it deletes it.

for example if the user deletes the id 45 from the table, an email must be sent saying "A user was deleted from the table: 'Name','Phone','Extension'"

code for the 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>
  • 写回答

2条回答 默认 最新

  • dongmei8071 2017-02-01 06:38
    关注

    You must fetch user data before delete. Do something like this

    <?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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了