我是 php 新手,今年夏季学期一直在参加 php 编程课程,我想知道是否有人可以帮助我弄清楚我需要做什么才能使事情正常进行。
我正在做一个最终项目,我们必须在我们想要的主题上建立我们的小数据库。所以我选择做一个电影数据库。我已经使用了 murach 的 php 书中 my_guitar_shop 中的一些代码。这是 Murach 的 php 和 mysql 书。并且由于某种原因,当我转到 index.php 页面时,我无法让我的信息显示在我页面上的表格中。
我将向您展示我的索引页面的代码
<?php
require_once('database.php');
if (isset($_POST['deleteThis'])) {
    $deleteThis = $_POST['deleteThis'];
    $sqlDel="DELETE FROM categories WHERE categoryID = $deleteThis";
    $temp=$db->exec($sqlDel);
}
// Get all categories
$query = 'SELECT * FROM categories
ORDER BY categoryID';
$categories = $db->query($query);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
    xmlns="http://www.w3.org/1999/xhtml">
<!-- the head section -->
<head>
<title>My Movie Store</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<!-- the body section -->
<body>
    <center>
        <div id="heading">My Movie Store</div>
    </center>
    <div id="page">
        <div id="header">
            <h1>Top Movies</h1>
        </div>
        <div id="main">
            <h1>Movie List</h1>
            <table class="content">
                <tr>
                    <th>Title</th>
                    <th>Date</th>
                    <th> </th>
                </tr>
                <?php foreach($categories as $cat) {
                    ?>
                <tr>
                    <td><?php echo $cat['categoryName'];?>
                    </td>
                    <form method="post" action="category_list.php">
                        <input type="hidden" name="deleteThis"
                            value="<?php echo $cat['categoryID']; ?> " />
                        <td></td>
                        <td><input type="submit" value="Delete" />
                        </td>
                    </form>
                    <?php
                }
                ?>
            </table>
            <br />
            <h2>Add a Movie</h2>
            <!-- add code for the form here -->
            <p>
                <a href="add_product_form.php">Add Movie</a>
            </p>
            <br />
            <p>
                <a href="index.php">Movie List</a>
            </p>
        </div>
        <!-- end main -->
        <div id="footer">
            <p>
                ©
                <?php echo date("2012"); ?>
                My Movie Store, created by Kara Holey
            </p>
        </div>
    </div>
    <!-- end page -->
</body>
</html>
我的数据库名称称为我在 localhost/phpmyadmin 中创建的电影数据库,数据库下的 2 个表称为类别和电影。出于某种原因,这是我在此页面上遇到的错误。
警告:第 82 行 C:\xampp\htdocs\1306\finalp\index.php 中为 foreach() 提供的参数无效
如果有人可以帮助我,那就太好了。