php mysql页面不显示来自mysql表行

时间:2018-03-29 15:54:16

标签: php mysql

当我运行此操作时,我没有收到任何错误,也没有数据。我做错了什么?

这是我的代码:

<?php
include 'connnectionmsql.php';

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);

    //Query

    $sql = $conn->prepare("SELECT carid, carname FROM Cars WHERE carid = '1578'"); 

    $sql->execute() ;

?>
<div id="contents">
    <header>
        <div id="top">
            <div class="h2">
                <?php while( $row = $sql->fetch()) : ?>
                <h1><span><?php echo $row['carname']; ?></span>
                <?php endwhile ?>

0 个答案:

没有答案