php - 电子邮件消息不显示 mysql 列

标签 php mysql email

当我的客户完成注册表后,我会发送一封确认电子邮件,其中包含登录使用区域的凭据。收到电子邮件后,不会显示某一字段(agentid) - 所有其他字段均正确显示。 这是我的代码片段

 mysql_query("  INSERT INTO tz_introducers(usr,pass,email,regIP,dt,introid,introducer,officeid,office)
                    VALUES(

                        '".$_POST['username']."',
                        '".md5($pass)."',
                        '".$_POST['email']."',
                        '".$_SERVER['REMOTE_ADDR']."',
                        NOW(),
                        '".$_POST['introid']."',
                        '".$_POST['introducer']."',
                        '".$_POST['officeid']."',
                        '".$_POST['office']."'
            )");

//I now set the field agentid equal to the autoincrement field, id

mysql_query("update tz_introducers set agentid= id where agentid is null");
$agentid= $_POST['agentid'] ;



    if(mysql_affected_rows($link)==1)
    {
        send_mail(  'registration@ISAdistribution.co.uk',
                    $_POST['email'],
                    'Registration Confirmation - Your New Password',
                    "Thanks for Registering.\r\nYour Introducer ID is: {$_POST['introid']}\r\nYour Office ID is: {$_POST['officeid']}\r\nYour Office is: {$_POST['office']}\r\nYour Agent ID is: {$_POST['agentid']}\r\nYour Username is: {$_POST['username']}\r\nYour password is: {$pass}\r\n\r\n\r\n");  


        $_SESSION['msg']['reg-success']='We sent you an email with your new password!';
    }
    else $err[]='This username is already taken!';
}

if(count($err))
{
    $_SESSION['msg']['reg-err'] = implode('<br />',$err);
}   

header("Location: intrologin.php");
exit;

我不明白为什么在后续电子邮件中没有显示 agentid 字段。它只显示空白

感谢您提前提供的帮助

最佳答案

我相信您的 $_POST['agentid'] 仍然是 null,因此它不会显示。

尝试在 UPDATE 语句中使用 LAST_INSERT_ID(),而不是直接使用 auto_increment ID 列,例如

mysql_query("update tz_introducers set agentid= LAST_INSERT_ID() where agentid is null");   

编辑:

我对 PHP 的了解非常少;回答这个问题只是因为它与 MySQL 相关。但从您最后的评论来看,您的 $_POST['agentid'] 似乎是 NULLundefined ,因此下面的行设置 $agentid 也为 null,即使 UPDATE 成功。

$agentid = $_POST['agentid'];

我认为您应该使用mysql_insert_id()来设置$agentid,如下所示,然后在您的电子邮件中使用$agentid

$agentid = mysql_insert_id();

关于php - 电子邮件消息不显示 mysql 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30685597/

相关文章:

email - 非 ASCII 电子邮件地址和 SMTP

c# - 无法使用 mailto uri 创建具有多个收件人的新邮件

javascript - JQUERY 响应不工作

php - 将 php 查询放入数组中

php - 如何去除 PHP 变量中的空格?

php - 如何将mysql中的两列合并为一列?

mysql - 连接到 tutum 端点上的 mysql docker

php - 是否可以使用在 URL 中传递的值来查询数据库,并使用 mod_rewrite 将查询结果写入 URL?

c# - 我想从 mysql 数据库检索图像,但出现错误 "system parameter is not valid at system drawing image fromstream... "

mysql - 从带有外键的表中删除