user1302775
user1302775

Reputation: 195

PDO fetch table not working

I'm try to use the following script to fetch user data from a table

//if session detected connect to database using pdo
$db = getConnection();

$user = getUser();

//qry the databse
$stmt = $db->prepare("SELECT * FROM saved_holidays WHERE subscriberID = :email");
$stmt->bindParam(":email", $user);


echo "<br></br>
    <table border='2' align='left' width='700'>
    <th align='left'>HolidayID</th>
    <th align='left'>SubscriberID</th>
    <th align='left'>Link</th>
    <th align='left'>Published</th>
    <th align='left'>Title</th>
    <th align='left'>Description</th>
    <th align='left'>Saved</th>
    <br></br>
    <br></br>";

while($obj = $stmt->fetchObject())

{
    echo "<tr><td>".$obj->holidayID."</td><td>".$obj->subcriberID."</td><td>".$obj->link."</td><td>".
    $obj->pubDate."</td><td>".$obj->title ."<td>".$obj->dateSaved."</td><br/>\n"."</td></tr>";
}

echo "</table>
    <br></br>
    <br></br>"; 

I don't receive any error messages, but neither do I recieved the desire output. All I get is the table headings, what am doing wrong?

Upvotes: 1

Views: 395

Answers (1)

Madara&#39;s Ghost
Madara&#39;s Ghost

Reputation: 175098

Well, you don't execute your query.

$stmt->execute();

After a query is prepared, and all parameters/values are bound, you need to execute your query.

Upvotes: 1

Related Questions