不显示给定的数据

时间:2012-12-23 07:04:37

标签: php mysql

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数据库设置 Database

1 个答案:

答案 0 :(得分:2)

尝试更改

$query = mysql_query($query);

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

看看会发生什么