after test.html clicks on the query, the characters that need to be queried to call test.php, are also encoded by url, sent to test.php, and then mysqli calls the SQL statement.
Theprocess is very simple, and the code is here. You can query English, but you can"t handle Chinese characters.
here is test.html
$(function(){
$("-sharpSubmit").click(function(){
var key = escape($("-sharpkey").val());
var sel = $("-sharpsel").val();
if( key != 0 )
{
$.get("test.php",{key:key,sel:sel,sid:Math.random()},
function(data){
$("-sharpdisp").html(data);
});
}
else
{
$("-sharpdisp").html("");
}
});
});
</script>
<h2 align="center" style="margin:4px">ajax</h2>
<div style="border:1px solid gray;background:-sharpeee;padding:4px">
:
<input id="key" type="text">
<select id="sel" name="">
<option value="title"></option>
<option value="content"></option>
</select>
<input id="Submit" type="button" value="">
</div>
<div id="disp"></div>
</body>
</html>
<div id="disp"></div>
the test.php section is as follows
<?php
header("Content-type:text/html;charset=utf-8");
ini_set("display_errors", 1);
error_reporting(E_ALL);
include("conn.php");
$key = trim($_GET["key"]);
$sel = $_GET["sel"];
$sql = "select * from lyb";
if($key != ""){
$sql = $sql." where $sel like "%$key%";";
$result = $conn->query($sql);
}
if($result->num_rows > 0){ ?>
<?php echo $key ?>,<?php echo $result->num_rows ?>
<table>
<tr>
<th></th>
<th></th>
<th></th>
<th>email</th>
<th>ip</th>
</tr>
<?php while($row = $result -> fetch_assoc()){ ?>
<tr>
<td><?php echo $row["title"] ?></td>
<td><?php echo $row["content"] ?></td>
<td><?php echo $row["author"] ?></td>
<td><?php echo $row["email"] ?></td>
<td><?php echo $row["ip"] ?></td>
</tr>
<?php }?>
</table>
<?php }
else
echo "";
?>
query English
ajax)
call directly through data
select title,content from lyb where title like "%%";
+-----------------+-----------------------------------------+
| title | content |
+-----------------+-----------------------------------------+
| | |
| | |
| | |
| | |
| | |
| | utkj |
I"ve thought about it, which should be in test.php, where the problem
$key = trim ($_ GET ["key"]);
modify to
$key = unescape (trim ($_ GET ["key"]));
run error Call to undefined function unescape ()
excuse me, how to solve this problem?