在mysqli_stmt_get_result()之后代码停止运行

时间:2018-11-18 03:12:33

标签: php mysqli

我正在尝试制作一个简单的图片库,但是$result = mysqli_stmt_get_result($stmt);之后的所有内容都无法运行。请查看我的index.php文件:

<?php 
    $_SESSION['username'] = "Admin";
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Image Gallery</title>
</head>
<body>

    <main>
        <section class="gallery-links">
            <div class="wrapper">
                <h2>Gallery</h2>

                <div class="gallery-container">
                    <?php 
                    include_once 'includes/dbh.inc.php';

                    $sql = "SELECT * FROM gallery ORDER BY orderGallery DESC";
                    $stmt = mysqli_stmt_init($conn);

                    if (!mysqli_stmt_prepare($stmt, $sql)) {
                        echo "SQL statement failed!";
                    } else {
                        mysqli_stmt_execute($stmt);
                        $result = mysqli_stmt_get_result($stmt); // Nothing runs after this line

                        while ($row = mysqli_fetch_assoc($result)) {
                            echo '<a href="#">
                            <div style="background-image: url(img/'.$row["imgFullNameGallery"].');"></div>
                            <h3>'.$row["titleGallery"].'</h3>
                            <p>'.$row["descGallery"].'</p>
                        </a>';
                        }
                    }

                    ?>
                </div>


                <?php 



                if (isset($_SESSION['username'])) {
                    echo  '<div class="gallery-upload">
                    <form action="includes/gallery-upload.inc.php" method="POST" enctype="multipart/form-data">
                        <input type="text" name="fileName" placeholder="File name...">
                        <input type="text" name="fileTitle" placeholder="Image title...">
                        <input type="text" name="fileDesc" placeholder="Image description...">
                        <input type="file" name="file">
                        <button type="submit" name="submit">UPLOAD</button>
                    </form>
                </div>';
                }


                ?>

            </div>
        </section>
    </main>

</body>
</html>

我回显了很多消息,以测试我的代码何时停止工作,而正是它输入了$result = mysqli_stmt_get_result($stmt);。我已经重读了我的代码多次,看看是否做过任何错别字,但是我一生都找不到任何错别字。我也用Google搜索了我的问题,但没有找到任何解决方案。

0 个答案:

没有答案