仕事用の在庫システムを構築しています。データベースを検索するための検索システムが既にあります。しかし、名前にスペースが含まれているアイテムを検索すると、結果が見つかりません。これが私のスクリプトです。
<?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());
}