【问题标题】:Getting failed when everything right一切正常时失败
【发布时间】:2018-12-29 11:04:36
【问题描述】:

我正在尝试获取电子邮件内容并将其放入 mysqli 表中。 基本上是它的硬币支付电子邮件,当有存款到一个地址时发送。由于他们没有存款历史的 api,我尝试开发一个电子邮件阅读器,它可以阅读电子邮件并将地址、用户名和 txid 放入存款表中。分解为数组时的电子邮件如下所示

 Array ( [0] => -----BEGIN [1] => PGP [2] => SIGNED [3] => MESSAGE-----Hash: 
 [4] => SHA256Hello [5] => an user [6] => deposit [7] => of [8] => 
 an amount [9] => LTCT [10] => has [11] => been [12] => received [13] => 
 and [14] => confirmed [15] => into [16] => your [17] => CoinPayments [18] 
 => Wallet. [19] => The [20] => deposit [21] => was [22] => received [23] => 
 on [24] => an address [25] => with [26] => 
 transaction [27] => ID [28] => 
 an txid.Thank [29] 
 => you [30] => for [31] => using [32] => CoinPayments.net!Support [33] => 
 is [34] => available [35] => at: [36] => https://www.coinpayments.net/help- 
 support-----BEGIN [37] => PGP [38] => SIGNATURE----- 
 END [39] => PGP [40] => SIGNATURE----- )

现在我尝试使用 imap 获取最近的电子邮件,将其删除并将变量放入存款表中。

   <?php
   $hostname = "{imap.gmail.com:993/imap/ssl/novalidate-cert}Inbox";
   $username = 'username';
   $password = 'password';

    $inbox = imap_open($hostname,$username,$password) or die('Cannot connect: ' . imap_last_error());

  $emails = imap_search($inbox,'ALL');


  if($emails)
 {
$output = '';

rsort($emails);

  $email_number = $emails[0];
{


    $message = quoted_printable_decode(imap_fetchbody($inbox,$email_number,1.1)); 
    if($message == '')
    {
        $message = (imap_fetchbody($inbox,$email_number,1));
        $str =  "$message";
        $explode = (explode(" ",$str));
        $check = $explode[20];
        if ($check =='deposit') {
            $address = $explode[24];
            $textsplit = "$explode[28]";
            $split = (explode(".",$textsplit));
            $txid = $split[0];
            $signature = $explode[38];
            $date = date("Y-m-d");
            require ('setup.php');
                $conn = new mysqli($localhost, $hostuser, $hostpass, $hostdb) or die("conn died");
                $query1 = "SELECT user FROM addresses WHERE address = '$address'";  //Get username so i put it with txid in deposits table
               $result = $conn->query($query1);
                if ($result) {

             while ($row = mysqli_fetch_array($result)) {
              $user = $row['user'];
             }
                $query = "INSERT INTO deposits(tx, date, user, signature) VALUES('$txid', '$date', '$user', '$signature')";
                $result = mysqli_query($conn, $query);

    if($result) {
        echo 'inserted';
        $dl = imap_delete($inbox, $email_number);
        if ($dl) {
            echo 'deleted';
        }
        else {
            die('cant insert');
        }
    }
    else {
        die('failed1');
    }
        }
       else
       {
           die('failed');
       }


    }
}       
}
}

但最后我得到“失败1”。 我不认为有任何错误。如果可以的话请帮助我=)

【问题讨论】:

  • 如果您显示一些有意义的错误而不仅仅是 'failed1' - stackoverflow.com/questions/22662488/…
  • 给我一个声明然后我会告诉你哪个错误
  • date 是 MySQL 关键字,不要使用 MySQL 关键字作为表/列名,处理起来很烦人。根据您想要做什么,您应该将其重命名为 createdAt

标签: php mysqli imap


【解决方案1】:

在此查询:

$result = mysqli_query($conn, $query);

替换为:

$result = $conn->query($query);

【讨论】:

  • 这更像是一种风格而不是错误 - stackoverflow.com/questions/16756002/…
  • @natashakrishnan 在这种情况下,请分享您遇到的确切错误。在执行之前打印确切的查询并尝试运行该查询并检查它是否正在插入数据。
猜你喜欢
  • 1970-01-01
  • 2020-04-26
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-05-09
  • 2010-12-14
相关资源
最近更新 更多