How to search for data from a select database using the Select drop-down menu and the text text box
For example, my drop-down list of secondary number, name, place of origin and other options, I selected "Hometown", and in the following text box enter "Beijing", click the Search button in the database corresponding to the native field to match, and output the final result. I'm using Php+mysql, do I have a problem with the code below? The feature is always not implemented and the display record is 0.
HTML page:
PHP Page:
Error_reporting (e_all ^ e_notice);
$dbhost = "localhost";
$dbuser = "root";
$dbpassword = "";
$db = mysql_connect ($dbhost, $dbuser, $dbpassword);
mysql_query ("SET NAMES ' UTF8 '");
mysql_select_db ("Lxshfile");
if (Isset ($_get["Action"]) &&$_get["action"]== "search") {
$searchId =$_post["SearchOption"];
$keyword =$_post["keyword"];
$sqltext = "SELECT * from Lxsh where ' $searchId ' like '% $keyword% '";
$result = mysql_query ($sqltext);
$row = Mysql_numrows ($result);
if ($keyword = = "") {
Echo
Please enter a keyword!
";
exit;//If no keyword is entered, the program is closed
}
else{
Echo ("
Search Result: Total ". $row." Article Records
");
Echo ("
School Number | "); Echo ("
Name | "); Echo ("
Origin |
"); while ($table = Mysql_fetch_array ($result))//Output data query data! {Echo ("
". $table [' XH ']." | "); Echo ("
". $table [' XM ']." | "); Echo ("
". $table [' JG ']." |
"); } Echo ("
");
}
}
?>
------Solution--------------------
' $searchId ' = ' $searchId ' or simply add nothing.
Mysql_num_rows
------Solution--------------------
$sqltext = "SELECT * from Lxsh where ' $searchId ' like '% $keyword% '";
Change this sentence to:
$sqltext = "SELECT * from Lxsh where $searchId like '% $keyword% '";
echo $sqltext;//can print out to see