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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?