Self-study PHP, do the search box encountered a problem, when I entered the search string as long as there is no space at the beginning of anything can be, he will all the table all the data are displayed, did not understand what is the problem, the amount, the code is such
if (Isset ($_get[' Sousuok ')) {
if (Ctype_space ($_get[' Sousuok ')) {
echo "Illegal data! ";
}else{
$s =explode ("", $_get[' Sousuok ']);
Require_once '. /connvar.php ';
$dbc =mysqli_connect (db_host,db_user,db_password,db_name);
mysql_query ("SET NAMES ' UTF8 '");
$exec = "SELECT * from Cangku where name like '% $s [0]% ' or '% $s [1]% ';";
$result =mysqli_query ($DBC, $exec);
if (Mysqli_num_rows ($result) >0) {
while ($rs =mysqli_fetch_object ($result)) {
$name = $rs->name;
$tu = $rs->biaoqiantu;
echo "
". $name." "."
";
};
echo mysqli_num_rows ($result);
}else{
echo mysqli_num_rows ($result);
echo "Not Found! ";
};
Mysqli_free_result ();//Release memory
Mysqli_close ();//Disconnect the database
}
}
?>
Reply to discussion (solution)
$s =explode ("", $_get[' Sousuok ']);
If $_get[' Sousuok ' begins with a space, then $s [0] is an empty string
So $exec = "SELECT * from Cangku where name like '% $s [0]% ' or '% $s [1]% ';";
It becomes $exec = "SELECT * from Cangku where name is like ' percent ' or '% query word% ';";
The name like ' percent ' is always set up, and nature is the whole thing.