dongwaner1367 2019-01-28 22:46
浏览 41
已采纳

有多个数据库交互和电子邮件更新cron作业时遇到问题

New server has latest php and MariaDB, existing outdated code on cron job with more than one call to and from database with email notification no longer returns expected results.

Moved to new server, website built years ago by volunteers, I have tried changing how php interacts with database using mysqli changes I have read about, worked on all other basic pages but multiple calls using sql1, sql2 etc not functioning.

<?php
$headers = "MIME-Version: 1.0
" ;
$headers .= "From: member@trbncom.com
";
$headers .= "Content-Type: text/html; charset=ISO-8859-1
";
$dbh=MySQLi_connect ("localhost", "trbncom_main", "password!") or die ('I cannot connect to the database because: ' . MySQLi_error());
MySQLi_select_db ("trbncom_main");
$sql="select * from members where active='on' and mmonth='$renewalmonth' and mdate='$renewaldate'";
$result=MySQLi_query($sql); 
while($myrow=MySQLi_fetch_array($result))
{
$chapter=$myrow["chapter"];
$mdate=$myrow["mdate"];
$mmonth=$myrow["mmonth"];
$myear=$myrow["myear"];
$lname=$myrow["lname"];
$fname=$myrow["fname"];
$firstnotice=$myrow["firstnotice"];
$sent1st=$myrow["sent1st"];
$sent2nd=$myrow["sent2nd"];
$sentoverdue=$myrow["sentoverdue"];

echo("<br>$lname, $fname<br>Joined on $mmonth, $mdate, $myear<br>$chapter, CID= $cid");

    $sql2="select lname, fname, email from members where cid='$cid' and active='on' and admin='pres'";
    $result2=MySQLi_query($sql2); 
    while($myrow2=MySQLi_fetch_array($result2))
    {
    $fname2=$myrow2["fname"];
    $lname2=$myrow2["lname"];
    $email2=$myrow2["email"];

echo("<br>$lname2, $fname2<br>$email2");

mail("member@trbncom.com","$fname $lname Membership is up for Renewal","<span style='color: #000080; font-size:12px; font-family: tahoma,arial,helvetica,sans-serif;'>Hello $fname<br><br>

Another year has come and gone and it's time to renew your membership
Sincerely<br>
Membership Committee<br>
</span>","$headers");

$sent=date("d M Y");
$sql3="update members set sent1st= '$sent', firstnotice='yes' where mid=$mid"; 
$result3=MySQLi_query($sql3);
}}
?>

The file does discover members with due dates on this day, it does email the list of members to me, it does not retrieve the sql2 query or update the table in the sql3 update. I dumped all my previous mysqli update attempts and reverted to the original code that worked before update, and have displayed it.

  • 写回答

1条回答 默认 最新

  • douxuanma4357 2019-01-28 23:22
    关注

    When using MySQLi_query you need to pass also the database handle $dbh, or link, that you established with the call to MySQLi_connect.

    So, for example:

    $dbh = MySQLi_connect ("localhost", "trbncom_main", "password!") or die ('I cannot connect to the database because: ' . MySQLi_error());
    
    MySQLi_select_db ($dbh, "trbncom_main");
    
    $sql="select * from members where active='on' and mmonth='$renewalmonth' and mdate='$renewaldate'";
    
    $result=MySQLi_query($dbh, $sql); 
    
    ...
    

    Check documentation carefully: this is easy to miss. Hope this helps.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来