PHP MYSQL查询当我搜索名称中有空格的项目时,它找不到任何结果

PHP MYSQL查询当我搜索名称中有空格的项目时,它找不到任何结果,php,mysql,search,spaces,Php,Mysql,Search,Spaces,我正在建立一个库存系统的工作,我有一个搜索系统来搜索数据库已经。但是,当我搜索名称中有空格的项目时,它找不到任何结果。这是我的剧本,任何帮助都将不胜感激 <?php // we connect to our Database mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("inventory") or die(mysql_error());

我正在建立一个库存系统的工作,我有一个搜索系统来搜索数据库已经。但是,当我搜索名称中有空格的项目时,它找不到任何结果。这是我的剧本,任何帮助都将不胜感激

    <?php
    // we connect to our Database
    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("inventory") or die(mysql_error());

    $find = $_POST['find'];

    echo "<h2>Search Results:</h2><p>";
    //If they did not enter a search term we give them an error
    if ($find == "")
    {
    echo "<p>You forgot to enter a search term!";
    exit;
    }

    // We perform a bit of filtering
    $find = strtoupper($find);
    $find = strip_tags($find);
    $find = trim ($find);

    //Now we search for our search term, in the field the user specified
    $data = mysql_query("SELECT * FROM parts WHERE vendor LIKE'%$find%' OR category
    LIKE'%$find%' OR prtid LIKE'%$find%' OR description LIKE '%$find%'");
    if (!$data) { // add this check.
    die('Invalid query: ' . mysql_error());
}

%
将只在整个搜索文本的外部插入通配符。如果要处理多个单词搜索字符串,则需要编写更复杂的查询

$searchTerms = explode(' ', $find);
$searchTermBits = array();
foreach ($searchTerms as $term) {
    $term = trim($term);
    if (!empty($term)) {
        $searchTermBits[] = "vendor LIKE '%$term%'";
    }
}

然后在查询中,只需内爆$searchTermBits而不是$term

什么搜索词在搜索文本时失败?为什么要修剪它-编辑-哦,nm-找不到任何空格?我想说发布的文本是编码的,您需要url解码parm值。请确保在查询中使用mysql\u real\u escape\u字符串如果我搜索与数据库中的零件号相同的零件号,如420 99 4710 00 04,则结果显示该零件号不在我的数据库中!