0

我有这个代码用于在 mysql 中搜索并且它正在工作但是当我运行并输入一个帐号时,它会显示我数据库中的所有帐户我只想显示我查询的帐号的详细信息。

我应该更改或添加什么?我不知道

<?php

echo "<h2>Search Results:</h2><p>";

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

// Otherwise we connect to our Database
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

// 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 Account_Number, Name, Balance FROM memaccounts WHERE ID    
LIKE'%$find%'");

//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['Account_Number'];
echo " ";
echo $result['Name'];
echo "<br>";
echo $result['Balance'];
echo "<br>";
echo "<br>";
}


$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query...<br><br>";
}

//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
//} 
?>  
4

1 回答 1

0
$data = mysql_query("SELECT Account_Number, Name, Balance FROM
 memaccounts WHERE Account_Number  = '" . trim($find) . "' ");

1.where with Ac no.

建议:使用mysqli_*

于 2013-07-24T08:33:03.220 回答