- 论坛徽章:
- 0
|
我的Mysql是winxp下的,我在mysql下查看:
show variables like '%char%'和show variables like '%collation%'
都是utf-8格式的(除了character_set_filesystem是 binary),我建立
数据库和表都是utf8的:
create database if not exists fw2015 default character set utf8 collate utf8_general_ci;
和create table if not exists seller (scode char( primary key, sname varchar(50),city varchar(20)) Type=MyISAM character set utf8;
我插入和显示的php:
主要的部分:
<form id="form1" name="form1" method="post" action="inssid.php">
<p>
<span class="STYLE4">
<label> 单位代码
<input name="scode" type="text" id="scode" />
</label>
</span> </p>
<p>
<label> 单位名称
<input name="sname" type="text" id="sname" />
</label></p>
<p>
<label> 城市名称
<input name="city" type="text" id="city" />
</label></p>
<p> </p>
<p> </p>
<p>
<input type="submit" name="Submit" value="提交" />
<label>
<input type="reset" name="Submit2" value="重置" />
</label>
</p>
</form>
文件inssid.php:
<?php
$db_host='127.0.0.1'; /*SQL服务器地址*/
$db_username='root'; /*登录SQL服务器的用户名*/
$db_password=''; /*登录SQL服务器的密码*/
$db_database='fw2015'; /*SQL中的数据库名称*/
$scode_p=$_POST['scode']; /*从表单中*/
$sname_p=$_POST['sname'];
$city_p= $_POST['city'];
$connection=mysql_connect($db_host,$db_username,$db_password); /*连接到SQL数据库的服务器*/
$db_selecct=mysql_select_db($db_database);/*选择SQL的数据库*/
$query="insert into seller(scode,sname,city) values ('".$scode_p."','".$sname_p."','".$city_p."')";
$result=mysql_query($query);/*执行查询*/
mysql_close($connection);
?>
显示php文件:
<?php
header("Content-Type: text/html;charset=UTF-8"
$db_host='127.0.0.1'; /*SQL服务器地址*/
$db_username='root'; /*登录SQL服务器的用户名*/
$db_password=''; /*登录SQL服务器的密码*/
$db_database='fw2015'; /*SQL中的数据库名称*/
$scode_p="87"; /*从表单中*/
$connection=mysql_connect($db_host,$db_username,$db_password); /*连接到SQL数据库的服务器*/
$db_selecct=mysql_select_db($db_database);/*选择SQL的数据库*/
$query="select * from seller where scode like '".$scode_p."%'";
$result=mysql_query($query);/*执行查询*/
?>
<?php
echo "<table border=2>";
echo "<tr> <th>厂家id</th> <th>厂家名称</th> <th>城市</th></tr>";
while($result_row=mysql_fetch_row($result))
{
$nmid=$result_row[0];
$nm=$result_row[1];
$unt=$result_row[2];
echo "<tr><td>";
echo $nmid;
echo "</td><td>";
echo $nm;
echo "</td><td>";
echo $unt;
echo "</td></tr>";
}
echo "</table>";
mysql_close($connection);
?>
可是显示出来的是乱码,请问怎么解决?
|
|