-3

PHP 文件不显示任何错误,但不显示要从 MySQL 数据库获取的数据。这并不是说它无法连接到数据库所以我不知道这次我是如何破坏它的 :( 搜索引擎

<body>
    <h2>Search Engine</h2>
    <form action='./search.php' method='get'>
        <input type='text' name='k' size='50' value='<?php echo $_GET['k'] ?>' />
        <input type='submit' value='Search'/>
    </form>
        <hr />
    <?php
        $k = $_GET['k'];
        $terms = explode(" ", $k);
        $query = "SELECT * FROM search WHERE ";

        foreach ($terms as $each)
        {
            //....
        }

        //connect
        mysql_connect("localhost", "root", "");
        mysql_select_db("search");

        $query = mysql_query($query);

        $num_rows = 0;
        if ($query){
            while($row = mysql_fetch_assoc($query)){
                $id = $row['id'];
                $title = $row['title'];
                $description = $row['description'];
                $k = $row['Keywords'];
                $link = $row['link'];
                echo "<h2><a href='$link'>$title</a></h2>
                $description<br /><br />";
            }
        }
        else
            echo "No results found for \"<b>$k</b>\"";

        //disconnect
        mysql_close();

    ?>
</body>
</html>

然后我有 MySQL 数据库设置 数据库

4

1 回答 1

2

尝试改变

$query = mysql_query($query);

$query = mysql_query($query) or die(mysql_error());

看看会发生什么

于 2012-12-23T07:07:14.420 回答