我有一个表单,可以将用户添加到mysql数据库表中,并将新信息通过电子邮件发送到地址(正常工作)。
现在我有一个用于从表中删除记录的表单,但我无法在删除它之前通过电子邮件发送旧用户数据。
例如,如果用户从表中删除了id 45,则必须发送一封电子邮件,说“用户已从表中删除:'姓名','电话','扩展'”
delete.php的代码:
function recurse($array,&$new)
{
foreach($array as $key => $value) {
if(is_array($value)) {
recurse($value,$new);
}
else {
if(!empty($value)) {
$exp = array_filter(explode(',',$value));
$new = array_merge($new,$exp);
}
}
}
}
# Create a storage array
$new = array();
# Run the recursive function
recurse($sample,$new);
# Show count
print_r(count($new));
答案 0 :(得分:0)
看起来代码还没有完成!
在表单提交上,首先使用WHERE id = $this_Stud_ID
获取数据
并执行
mail("yourname@domain.com","Subject","phone no name ..etc");
然后你可以执行
mysql_query("DELETE FROM users WHERE id = '$this_Stud_ID'")
or die(mysql_error());
请发布完整的代码!
答案 1 :(得分:0)
您必须在删除前获取用户数据。 做这样的事情
<?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>