连接完数据库,在取值前加上
mysql_query("SET NAMES ***");
***要和你页面上的编码一样就行
mysql_query("SET NAMES ***");
***要和你页面上的编码一样就行
解决方案 »
- 如何循环一个table并获取每行td中的值
- windows xp php mysqli扩展装不起
- ajax和JavaScript调用的问题.
- session 禁止 cook的问题
- utf8问题。从UTF8页面中提交数据转GB2312
- 怎么使windows2000下的php.ini文件起作用。
- 关于框架页面的刷新问题???!!
- 请问:在PHP中,不用图像函数库内的函数,如何取得一个图像文件的长与宽呢?
- 关于数据库链接问题!
- Php怎么做无闪烁刷新的聊天室!用socket可以做吗?asp里面有好多讨论,不过没有在php里面看到过!
- 这段代码错在哪里?判断客户端是否存在Cookie怎么判断(PHP)
- Warning: Cannot modify header information ,谢谢
<head> <title>Book-O_Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php
//create short variable names
$searchtype=$_POST['searchtype'];
$searchterm=$_POST['searchterm'];
$searchterm=trim($searchterm);
if(!$searchtype||!$searchterm)
{
echo 'You have not entered search details. Please go back and try again.';
exit;
}
if(!get_magic_quotes_gpc())
{
$searchtype=addslashes($searchtype);
$searchterm=addslashes($searchterm);
}
@ $db=new mysqli('localhost','liuchao','liuchao','books');//分别连接的是本地主机、用户名、密码、数据库名
if(mysqli_connect_errno())
{
echo 'Erro: Could not connect to database. Please try again later.';
exit;
}
$query="select * from books where ".$searchtype." like '%".$searchterm."%'";//实际类型之间的匹配
$result=$db->query($query);
//$num_results=$result->num_rows;//对象
$num_results=mysqli_num_rows($result);//过程式
echo '<p>Number of books found:'.$num_results.'</p>';
for($i=0;$i<$num_results;$i++)
{
$row=$result->fetch_assoc();
echo '<p><strong>'.($i+1).'.Title:';
echo htmlspecialchars(stripslashes($row['title']));
echo '</strong><br/>Author:';
echo stripslashes($row['author']);
echo '<br/>ISBN:';
echo stripslashes($row['isbn']);
echo '<br/>Price:';
echo stripslashes($row['price']);
echo '</p>';
}
//$result->free();
mysqli_free_result($result);
$db->close();
?>
</body>
</html>
这是我的代码,该怎么加啊,急
上面写$db->query("SET NAMES 'UTF-8'")你的所有的文件都要存成UTF-8,页面设置的字符级也是UTF-8