当我的客户完成注册表后,我会发送一封确认电子邮件,其中包含登录使用区域的凭据。收到电子邮件后,不会显示某一字段(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']
似乎是 NULL
或 undefined
,因此下面的行设置 $agentid
也为 null,即使 UPDATE
成功。
$agentid = $_POST['agentid'];
我认为您应该使用mysql_insert_id()
来设置$agentid
,如下所示,然后在您的电子邮件中使用$agentid
。
$agentid = mysql_insert_id();
关于php - 电子邮件消息不显示 mysql 列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30685597/