简体   繁体   English

使用PHP MYSQL的搜索方法

[英]Search method using PHP MYSQL

I'm trying to use search as my retrieve option, this is my simpliest form of searching, what can I do with these codes, No error but not working. 我正在尝试使用搜索作为我的检索选项,这是我最简单的搜索形式,这些代码我该怎么办,没有错误,但不起作用。 Please indicate what is wrong in my code. 请指出我的代码有什么问题。 Give advice, site, solution Thanks. 提供建议,网站,解决方案谢谢。

    <?php
    error_reporting(E_ALL); 
    ini_set('display_errors', 1);
    session_start();
    ob_start();

//connetion database
    $dbhost = '192.168.0.9';
    $dbuser = 'dsc';
    $dbpass = 'csd';

    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('ERROR CONNECTING TO MYSQL');

    $dbname = 'dbtips';
    mysql_select_db($dbname);

    $output='';

    if(isset($_POST['search']))
    {
        $searchq = $_POST['search'];
        $searchq = preg_replace("#[^0-9a-z]#i","",$searchq);

//query
        $query = mysql_query("SELECT * FROM tblnews WHERE udate LIKE '%$searchq%'");
        $count = mysql_num_rows($query);

        if($count==0)
        {
            $output = 'There was no search result!';
        }
        else
        {
            while($row = mysql_fetch_array($query)){
                   $udate = $row['udate'];
                   $mis = $row['mis'];
                   $status = $row['status'];



                   $output .= '->'.$udate.'-'.$mis.'-'.$status.'<br>'; 
    }
    }
    }
    ?>      

    //form for searching
    <form action="search.php" method="POST">
    <center>
    <p>
    <input type="text" size="90" name="search" style="text-align:center">
    <br>
    <br>
    <input type="button" name="searchbutton" value="Search">
    <br>
    <br>
    </p>
    </center>
    </form>

change this to 更改为

<input type="button" name="searchbutton" value="Search">

To this 对此

<input type="submit" name="searchbutton" value="Search">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM