0
的PHP:PHP/SQL错误在输出数据
<?php
$pID = filter_input(INPUT_GET, 'pID', FILTER_SANITIZE_NUMBER_INT);
if(!$pID) {
echo "No pID specified.";
exit;
}
$username = "###";
$password = "####";
$pdo = new PDO('mysql:host=localhost;dbname=###', $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $pdo->prepare('
SELECT D.name, P.lname, P.fname, P.picpath, P.email, C.info, C.date
FROM Department D, Professor P, Comment C
WHERE D.dID = P.dID
AND P.pID = C.pID;
');
$sth->execute(array(
$pID
));
?>
在同一页面中使用:
<?php
if($sth->rowCount() > 0) {
$row = $sth->fetch(PDO::FETCH_ASSOC);
echo "<img style='float:left;' src='img/profViewIcon.png' alt='Professor {$row['fname']} {$row['lname']} at Drexel' /><h1> <span title='{$row['fname']} {$row['lname']} at Drexel University'> {$row['fname']} {$row['lname']} </h1>";
echo "
<div class='professor_pic'>
<img src='{$row['picpath']}' />
</div><!-- /professor_pic -->
<div class='professor_desc'>
<span class='one' style='float:left; padding:5px 0 0 5px;'><strong>Department:</strong> {$row['name']} </span><br>
<span class='two' style='float:left; padding:5px 0 0 5px;'><strong>Email:</strong> {$row['email']} </span><br>
<span class='two' style='float:right;'>
<strong>Rating:</strong><img src='img/fullStar.png'><img src='img/fullStar.png'><img src='img/fullStar.png'><img src='img/halfStar.png'>
</span><br>
<span class='two' style='float:left; padding:20px 5px 0 5px; font-size:1.50em;'>
<img src='img/commentOnProf.png' class='left' /> <a href='#addComment' style='font-weight:bold;'>Write A Comment</a>
</span>
<span class='two' style='float:right; padding-right:5px;'>
<img class='left' width='24' height='24' src='img/posComment.png' /> Positive:18
<img src='img/negComment.png' width='24' height='24' /> Negative:10
<img width='24' height='24' src='img/neuComment.png' />Neutral:5
</span>
</div><!-- /professor_desc-->
<div id='clear'> </div>
<div class='professor_comments'>
"; // end echo
echo "
<h2 style='margin:0; padding:0;'>Recent Comments</h2>
<div class='comment'>by Anonymous on {$row2['date']}: <br> {$row2['info']} </div>
<input type='text' id='addComment' name='addComment' />
";
} else {
echo "No results.";
}
unset($sth);
?>
?>
为什么没有这个拉动FNAME,LNAME等价值观? ?
其拉动“By Anonoymous”部分,但没有任何值。任何人都