How to use the SELECT drop-down menu and TEXT box to search for data from the selected database, such as the student ID, name, and nationality in the drop-down list ", enter "Beijing" in the text box that follows, click the search button, and match the corresponding local field in the database, and output the final result. I use php + mysql. Is there any problem with the code below? There is always no way to implement the function. there are 0 display records.
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"
Enter keywords!
";
Exit; // if no keyword is entered, end the program
}
Else {
Echo ("
Search results: a total of ". $ row." records
");
Echo ("
| Student ID | ");Echo ("
Name | ");Echo ("
Nationality |
");While ($ table = mysql_fetch_array ($ result) // query data output!{Echo ("
| ". $ Table ['xh']." | ");Echo ("
". $ Table ['xm ']." | ");Echo ("
". $ Table ['JG']." |
");}Echo ("
");
}
}
?>
Reply to discussion (solution)
'$ Searchid' =>' $ searchid' or simply do not add anything.
Mysql_num_rows
I tried it, but I still can't. the quotation marks on $ searchId cannot be added or removed. Are there other methods?
I don't know where you can't do it. $ Row or 0?
$ Result = mysql_query ($ sqltext) or die (mysql_error ());
Post an error message.
$ Sqltext = "select * from lxsh where '$ searchId' like '% $ keyword % '";
Change this sentence:
$ Sqltext = "select * from lxsh where $ searchId like '% $ keyword % '";
Echo $ sqltext; // you can print it out.
$ Row = mysql_num_rows ($ result );
No
$ Row = mysql_numrows ($ result );
You wrote an error
Reply to the third and fourth floors:
If no error message is displayed, 0 results are displayed after you click search, and no search results are displayed.
For example, if I select "student ID" and enter "069", The Print result is as follows:
Select * from lxsh where like '% 100'
$ SearchId value is not obtained, and there is nothing behind where.
Reply to floor 5:
It has been modified, but no result is displayed. I don't know what is going on.
Reply to the third floor:
Sorry, the error message is as follows:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like' %'' at line 1"
Reply to the third floor:
Sorry, the error message is as follows:
"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'like' %'' at line 1"
Your $ keyword has a problem. The value may not be passed in. Check
Student ID
Name
Nationality
In the value settings, do you have the same name as in your database ?? If not, change it to the same name as the database!