-2

was hoping someone could give me some help... I'm using PDO to get some data from a database, but every time the script runs it comes back with no errors but won't display the required data, I KNOW that the data I'm looking for is in there too.. any help would be appreciated, this is what I have at the moment, thanks.

$db = new PDO('sqlite:C:\\xampp\\htdocs\\Utils\\PDF_Utils\\PDF2Word\\details.sqlite');

    echo "<table border=1>";
    echo "<tr><td>FileID</td>
              <td>File Name</td>
              <td>Email From</td>
              <td>CC</td> <td>Subject</td>
              <td>File Size</td></tr>";


              $contents = $db->prepare("SELECT * FROM details WHERE fileName = 
                         '$yourFileName'");
              $contents->execute();

                   foreach($contents as $row) {
                        echo "<tr><td>" . $row['FileID'] . "</td>";
                        echo "<td>" . $row['fileName'] . "</td>";
                        echo "<td>" . $row['emailFrom'] . "</td>";
                        echo "<td>" . $row['CC'] . "</td>";
                        echo "<td>" . $row['subject'] . "</td>";
                        echo "<td>" . $row['fileSize'] . "</td></tr>";
                    }
                    echo "</table>";
Daniel Morgan
  • 123
  • 1
  • 1
  • 8

3 Answers3

0
$stmt = $db->prepare("SELECT * FROM details WHERE fileName = ?"); 
$stmt->execute(array($yourFileName));
$contents = $stmt->fetchAll();

the rest is the same

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345
  • 1. it does NOT the same thing. 2. to have non-blank screen you have to [setup your PDO and PHP properly](http://stackoverflow.com/questions/15990857/reference-frequently-asked-questions-about-pdo#15990858) – Your Common Sense May 13 '13 at 10:34
  • Fixed it now, thanks for the help anyway but done it a different way. – Daniel Morgan May 13 '13 at 11:02
-1

Use a placeholder when preparing the statement and then execute the query passing the parameter, like this:

$contents = $db->prepare("SELECT * FROM details WHERE fileName = ?");
$contents->execute(array($yourFileName));

Then fetch the results using FETCH_ASSOC:

while($row = $contents->fetch(PDO::FETCH_ASSOC)){
     //your code here;
}
Ander2
  • 5,569
  • 2
  • 23
  • 42
  • It should be `array($yourFileName)` – hjpotter92 May 13 '13 at 10:27
  • @hjpotter92 missed that. Fixed. – Ander2 May 13 '13 at 10:29
  • @DanielMorgan are you sure your database and tables are ok and that there is no error? – Ander2 May 13 '13 at 10:38
  • Yep I am very sure, because what I'm doing is creating a system so that if a user sends an e-mail with a .pdf attachment to a specific e-mail address it will store the details of that e-mail in a sqlite database, and I know it's storing because it shows the details on the first page but not the second... – Daniel Morgan May 13 '13 at 10:41
  • @DanielMorgan Do actually your code's table name and fields name match your database's table and fields name's case (uppercase/lowercase)? – Ander2 May 13 '13 at 10:51
-1

put brackets around $yourFileName as {$yourFileName}

Luca Rocchi
  • 6,272
  • 1
  • 23
  • 23