0

Need some help here. I am trying to insert row value (email ids in this case), as a variable for further processing. The purpose is to decrypt the email ids which were saved encrypted and saved in the database. The code works fine on entering individual values (email ids) manually and it get decrypted fine. But it is not accepting results from the mysql query.

Here's the code.

<?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>";
}
?>

When I use $row or $result in input field ($input), it keeps on giving the error that $row or $result is not defined. How do I insert the result value in input field?

Regards, Anang

AFV
  • 51
  • 6
  • 1
    you mean `$input = $row;` is a problem? ...yes, well where is $row defined before that line? Nowhere that we can see. It's not clear what you're expecting to happen? What do you use $input for later on? I'm guessing that you need to be putting that inside your foreach loop, but it's not clear what the actual goal is so I can't tell you precisely what you should be doing instead. It's only clear that what you've got now doesn't really make sense. – ADyson Mar 05 '18 at 14:42

1 Answers1

0

You are calling $row before it is defined - you ought probably be trying like this where you call the aes class in the loop

<?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>";
?>
Professor Abronsius
  • 33,063
  • 5
  • 32
  • 46