当我用数字搜索一封信时显示错误?

时间:2016-03-15 03:39:36

标签: php

    mysql_connect("localhost", "root", "") or die(mysql_error());
    mysql_select_db("corporate_personnel_order_for_2016") or die(mysql_error());
    $search = $_GET['search'];
    $result = mysql_query("SELECT * FROM obs WHERE OBS_NUMBER LIKE $search;") or die(mysql_error());
echo "<table><tr><th width=250>OBS Number</th><th width=250>Name</th><th width=250>Purpose</th><th width=250>Date of OB</th><th width=250>Destination</th></tr>";



while ($row = mysql_fetch_array($result)) {
    echo '<table><tr>';
    echo '<td width=250>' . $row['OBS_NUMBER'] . '</td>';
    echo '<td width=250>' . $row['NAME'] . '</td>';
    echo '<td width=250>' . $row['PURPOSE'] . '</td>';
    echo '<td width=250>' . $row['DATE_OF_OB'] . '</td>';
    echo '<td width=250>' . $row['DESTINATION'] . '</td>';
    echo '</tr>';
echo "</table>";

当我搜索带有字母和数字的条目时,它无法显示错误但是当我搜索一个数字时它只显示在我的桌子上?

1 个答案:

答案 0 :(得分:1)

试试这个

$result = mysql_query("SELECT * FROM obs WHERE OBS_NUMBER LIKE '".$search."'") or die(mysql_error());

或者

$result = mysql_query("SELECT * FROM obs WHERE OBS_NUMBER LIKE '%".$search."%'") or die(mysql_error());