如何在变量中插入echo值?

时间:2018-03-05 14:39:07

标签: php mysql

需要一些帮助。我试图插入行值(在这种情况下为电子邮件ID),作为进一步处理的变量。目的是解密加密保存并保存在数据库中的电子邮件ID。 该代码可以手动输入单个值(电子邮件ID),并且可以解密。但它不接受mysql查询的结果。

这是代码。

<?php
include 'AES.php';
include 'db.php';

$input = $row;
$key = "key value";
$blockSize = 256;
$aes = new AES($input, $key, $blockSize);
$enc = $aes->encrypt();
$dec=$aes->decrypt();
$aes->setData($dec);

echo "Encrypted Value - ".$enc."<br/>";
echo "Decrypted Value - ".$dec."<br/>";

$sth = $pdo->prepare("SELECT email FROM tbl_subs");
$sth->execute();

print("<br>List of email IDs:\n <br><br>");
$result = $sth->fetchAll(\PDO::FETCH_ASSOC);
 foreach( $result as $row ){
   echo "<tr><td>";
     echo $row['email'];
     echo "</td><br>";
     echo "</tr>";
}
?>

当我在输入字段($ input)中使用$ row或$ result时,它会继续给出$ row或$ result未定义的错误。如何在输入字段中插入结果值?

此致 阿南

1 个答案:

答案 0 :(得分:0)

你在定义它之前调用$row - 你应该尝试这样做,你在循环中调用aes

<?php

    include 'AES.php';
    include 'db.php';


    $key = "key value";
    $blockSize = 256;

    $sth = $pdo->prepare("SELECT email FROM tbl_subs");
    $sth->execute();


    $result = $sth->fetchAll( PDO::FETCH_ASSOC );
    echo "<table>";
    foreach( $result as $row ){

        $aes = new AES( $row['email'], $key, $blockSize );
        $decrypted=$aes->decrypt();

        echo "
        <tr>
            <td>{$row['email']}</td>
            <td>{$decrypted}</td>
        </tr>";
        $aes=null;
    }
    echo "</table>";
?>