Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 没有错误,但查询不返回任何结果_Php_Mysql_Pdo - Fatal编程技术网

Php 没有错误,但查询不返回任何结果

Php 没有错误,但查询不返回任何结果,php,mysql,pdo,Php,Mysql,Pdo,没有显示任何内容,也没有输出错误。我已经定义了$id。有什么想法吗 <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); $stm

没有显示任何内容,也没有输出错误。我已经定义了
$id
。有什么想法吗

<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>

价格:

在您的SQL中,您尝试选择“价格”(较低的“p”),但您尝试回显$row2[“价格”](较高的“p”)。试试这个,或者将“Price”中的p改为小写

<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>

价格:

如果这不起作用,请在PHPMyAdmin中尝试SQL代码。如果显示数据,您的SQL将是正确的。

如果您期望并回答此问题,您应该合理地缩进代码。是否具有该ID的产品不在数据库中?尝试回显id的值并手动运行查询。我已经尝试在数据库上运行查询,但它工作正常,因此与查询无关。您是否检查了HTML?是否没有输出,或者TD标签是否出现?