简体   繁体   中英

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM