Nothing is showing, and no error is output. I have defined $id
. Any ideas?
<tr>
<td width="160">Price:</td>
<?php
dbconnect();
$stmt2 = $conn->prepare("SELECT Length, price FROM Product WHERE ProdID=:id LIMIT 1");
$stmt2->bindParam('id',$id);
$stmt2->execute();
$i = 0;
foreach ($stmt2->fetchAll(PDO::FETCH_ASSOC) as $row2) {
if ($i == 0) {
echo '<td>'.$row2['Price'].'</td>';
}
}
?>
</tr>
In you're SQL you try to select "price" (lower "p"), but you try to echo $row2['Price'] (upper "P"). Try this or change the p in "Price" to lowercase!
<tr>
<td width="160">Price:</td>
<?php
dbconnect();
$stmt2 = $conn->prepare("SELECT Length, Price FROM Product WHERE ProdID=:id LIMIT 1");
$stmt2->bindParam('id',$id);
$stmt2->execute();
$i = 0;
foreach ($stmt2->fetchAll(PDO::FETCH_ASSOC) as $row2) {
if ($i == 0) {
echo '<td>'.$row2['Price'].'</td>';
}
}
?>
</tr>
If this is not working, try your SQL-code in PHPMyAdmin. If the data will be displayed, your SQL would be right.