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>
    
    打赏 评论
  • dsb12300 2017-02-01 06:30

    Look like the code isn't complete ! On form submit first fetch the data with WHERE id = $this_Stud_ID and execute
    mail("yourname@domain.com","Subject","phone no name ..etc");
    then you can execute

    mysql_query("DELETE FROM users WHERE id = '$this_Stud_ID'")
    or die(mysql_error()); 
    

    Please post your complete code !

    打赏 评论

相关推荐 更多相似问题