How to search for data from a select database using the Select drop-down menu and the text text box

Source: Internet
Author: User
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 ("








"); Echo (" "); Echo (" "); while ($table = Mysql_fetch_array ($result))//Output data query data! {Echo (" "); Echo (" "); Echo (" "); } Echo ("
School NumberNameOrigin
". $table [' XH ']."". $table [' XM ']."". $table [' JG ']."
");
}
}
?>
------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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.