php输入数据库,显示为问号,而不是应该的中文?
php输入数据库,显示为问号,而不是应该的中文?$str_sql="INSERTINTO$tablename(user_name,user_password,user_g...
php输入数据库,显示为问号,而不是应该的中文?$str_sql="INSERT INTO $tablename(user_name,user_password,user_group)VALUES('$_POST[user_name]','$_POST[user_password]','$user_group')";echo $str_sql;echo "<br>";if(!mysql_query($str_sql,$link_id)){echo "无法输入";}else{echo "成功!";}这段程序向数据库中输入用户名和密码,但是当用户名为汉字时,数据库显示为“????”,这要怎么解决啊?我尝试这样:$str_sql='……',然后"$_POST",但是这样就不能输入数据库了!我又尝试了:/"$_POST/"。但是这样也无法输入数据库!请问高手怎么解决啊?
展开
展开全部
新建php页面时中文显示正常,插入记录集导航条和记录集导航数据时的文字是英文,当运行预览(F12)时,IE页面出现的中文乱码,英文能正常显示;
当从php页面提交插入记录并返回页面时,显示的提交内容没有乱码,只是在Dreamweaver制作时写入的中文是乱码;
然后打开http://localhost/phpmyadmin/页面查看数据库,发现刚才输入的中文显示为乱码;
这个时候,我在数据库里修改刚才输入的中文并保存,这时数据库能显示的是中文,但回到在php页面运行预览(F12)时,在数据库里修改的那部分出现的是很多问号(?),其他没有修改的内容没有变化。请各位高手出手相助!该如何修改才不会乱码?
1..安装的是appserv-win32-2.5.9及Dreamweaver CS3
2..在MySQL Command Line Client输入以下命令时:
mysql> SHOW CHARACTER SET;
+----------+-----------------------------+---------------------+--------+
| Charset | Description | Default collation | Maxlen |
+----------+-----------------------------+---------------------+--------+
| big5 | Big5 Traditional Chinese | big5_chinese_ci | 2 |
| dec8 | DEC West European | dec8_swedish_ci | 1 |
| cp850 | DOS West European | cp850_general_ci | 1 |
| hp8 | HP West European | hp8_english_ci | 1 |
| koi8r | KOI8-R Relcom Russian | koi8r_general_ci | 1 |
| latin1 | cp1252 West European | latin1_swedish_ci | 1 |
| latin2 | ISO 8859-2 Central European | latin2_general_ci | 1 |
| swe7 | 7bit Swedish | swe7_swedish_ci | 1 |
| ascii | US ASCII | ascii_general_ci | 1 |
| ujis | EUC-JP Japanese | ujis_japanese_ci | 3 |
| sjis | Shift-JIS Japanese | sjis_japanese_ci | 2 |
| hebrew | ISO 8859-8 Hebrew | hebrew_general_ci | 1 |
| tis620 | TIS620 Thai | tis620_thai_ci | 1 |
| euckr | EUC-KR Korean | euckr_korean_ci | 2 |
| koi8u | KOI8-U Ukrainian | koi8u_general_ci | 1 |
| gb2312 | GB2312 Simplified Chinese | gb2312_chinese_ci | 2 |
| greek | ISO 8859-7 Greek | greek_general_ci | 1 |
| cp1250 | Windows Central European | cp1250_general_ci | 1 |
| gbk | GBK Simplified Chinese | gbk_chinese_ci | 2 |
| latin5 | ISO 8859-9 Turkish | latin5_turkish_ci | 1 |
| armscii8 | ARMSCII-8 Armenian | armscii8_general_ci | 1 |
| utf8 | UTF-8 Unicode | utf8_general_ci | 3 |
| ucs2 | UCS-2 Unicode | ucs2_general_ci | 2 |
| cp866 | DOS Russian | cp866_general_ci | 1 |
| keybcs2 | DOS Kamenicky Czech-Slovak | keybcs2_general_ci | 1 |
| macce | Mac Central European | macce_general_ci | 1 |
| macroman | Mac West European | macroman_general_ci | 1 |
| cp852 | DOS Central European | cp852_general_ci | 1 |
| latin7 | ISO 8859-13 Baltic | latin7_general_ci | 1 |
| cp1251 | Windows Cyrillic | cp1251_general_ci | 1 |
| cp1256 | Windows Arabic | cp1256_general_ci | 1 |
| cp1257 | Windows Baltic | cp1257_general_ci | 1 |
| binary | Binary pseudo charset | binary | 1 |
| geostd8 | GEOSTD8 Georgian | geostd8_general_ci | 1 |
| cp932 | SJIS for Windows Japanese | cp932_japanese_ci | 2 |
| eucjpms | UJIS for Windows Japanese | eucjpms_japanese_ci | 3 |
+----------+-----------------------------+---------------------+--------+
36 rows in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'character_set_%';
+--------------------------+----------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | C:\AppServ\MySQL\share\charsets\ |
+--------------------------+----------------------------------+
8 rows in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'collation_%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
3..在Dreamweaver CS3新建php页面时有以下代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4..进入http://localhost/phpmyadmin/页面显示:
localhost
服务器版本: 5.0.45-community-nt-log
Protocol version: 10
MySQL 字符集: UTF-8 Unicode (utf8)
MySQL 连接校对:utf8_general_ci
phpMyAdmin - 2.10.2
MySQL client version: 5.0.37
Language: 中文-Chinese simplified
其中,打开了数据库列表显示如下:
数据库 整理
mymy2012 utf8_general_ci
mysql utf8_general_ci
phpmyadmin utf8_bin
test utf8_general_ci
统计: 4 utf8_general_ci
新建php页面时中文显示正常,插入记录集导航条和记录集导航数据时的文字是英文,当运行预览(F12)时,IE页面出现的中文乱码,英文能正常显示;
当从php页面提交插入记录并返回页面时,显示的提交内容没有乱码,只是在Dreamweaver制作时写入的中文是乱码;
然后打开http://localhost/phpmyadmin/页面查看数据库,发现刚才输入的中文显示为乱码;
这个时候,我在数据库里修改刚才输入的中文并保存,这时数据库能显示的是中文,但回到在php页面运行预览(F12)时,在数据库里修改的那部分出现的是很多问号(?),其他没有修改的内容没有变化。请各位高手出手相助!该如何修改才不会乱码?
当从php页面提交插入记录并返回页面时,显示的提交内容没有乱码,只是在Dreamweaver制作时写入的中文是乱码;
然后打开http://localhost/phpmyadmin/页面查看数据库,发现刚才输入的中文显示为乱码;
这个时候,我在数据库里修改刚才输入的中文并保存,这时数据库能显示的是中文,但回到在php页面运行预览(F12)时,在数据库里修改的那部分出现的是很多问号(?),其他没有修改的内容没有变化。请各位高手出手相助!该如何修改才不会乱码?
1..安装的是appserv-win32-2.5.9及Dreamweaver CS3
2..在MySQL Command Line Client输入以下命令时:
mysql> SHOW CHARACTER SET;
+----------+-----------------------------+---------------------+--------+
| Charset | Description | Default collation | Maxlen |
+----------+-----------------------------+---------------------+--------+
| big5 | Big5 Traditional Chinese | big5_chinese_ci | 2 |
| dec8 | DEC West European | dec8_swedish_ci | 1 |
| cp850 | DOS West European | cp850_general_ci | 1 |
| hp8 | HP West European | hp8_english_ci | 1 |
| koi8r | KOI8-R Relcom Russian | koi8r_general_ci | 1 |
| latin1 | cp1252 West European | latin1_swedish_ci | 1 |
| latin2 | ISO 8859-2 Central European | latin2_general_ci | 1 |
| swe7 | 7bit Swedish | swe7_swedish_ci | 1 |
| ascii | US ASCII | ascii_general_ci | 1 |
| ujis | EUC-JP Japanese | ujis_japanese_ci | 3 |
| sjis | Shift-JIS Japanese | sjis_japanese_ci | 2 |
| hebrew | ISO 8859-8 Hebrew | hebrew_general_ci | 1 |
| tis620 | TIS620 Thai | tis620_thai_ci | 1 |
| euckr | EUC-KR Korean | euckr_korean_ci | 2 |
| koi8u | KOI8-U Ukrainian | koi8u_general_ci | 1 |
| gb2312 | GB2312 Simplified Chinese | gb2312_chinese_ci | 2 |
| greek | ISO 8859-7 Greek | greek_general_ci | 1 |
| cp1250 | Windows Central European | cp1250_general_ci | 1 |
| gbk | GBK Simplified Chinese | gbk_chinese_ci | 2 |
| latin5 | ISO 8859-9 Turkish | latin5_turkish_ci | 1 |
| armscii8 | ARMSCII-8 Armenian | armscii8_general_ci | 1 |
| utf8 | UTF-8 Unicode | utf8_general_ci | 3 |
| ucs2 | UCS-2 Unicode | ucs2_general_ci | 2 |
| cp866 | DOS Russian | cp866_general_ci | 1 |
| keybcs2 | DOS Kamenicky Czech-Slovak | keybcs2_general_ci | 1 |
| macce | Mac Central European | macce_general_ci | 1 |
| macroman | Mac West European | macroman_general_ci | 1 |
| cp852 | DOS Central European | cp852_general_ci | 1 |
| latin7 | ISO 8859-13 Baltic | latin7_general_ci | 1 |
| cp1251 | Windows Cyrillic | cp1251_general_ci | 1 |
| cp1256 | Windows Arabic | cp1256_general_ci | 1 |
| cp1257 | Windows Baltic | cp1257_general_ci | 1 |
| binary | Binary pseudo charset | binary | 1 |
| geostd8 | GEOSTD8 Georgian | geostd8_general_ci | 1 |
| cp932 | SJIS for Windows Japanese | cp932_japanese_ci | 2 |
| eucjpms | UJIS for Windows Japanese | eucjpms_japanese_ci | 3 |
+----------+-----------------------------+---------------------+--------+
36 rows in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'character_set_%';
+--------------------------+----------------------------------+
| Variable_name | Value |
+--------------------------+----------------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | C:\AppServ\MySQL\share\charsets\ |
+--------------------------+----------------------------------+
8 rows in set (0.00 sec)
mysql> SHOW VARIABLES LIKE 'collation_%';
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_general_ci |
| collation_database | utf8_general_ci |
| collation_server | utf8_general_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
3..在Dreamweaver CS3新建php页面时有以下代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4..进入http://localhost/phpmyadmin/页面显示:
localhost
服务器版本: 5.0.45-community-nt-log
Protocol version: 10
MySQL 字符集: UTF-8 Unicode (utf8)
MySQL 连接校对:utf8_general_ci
phpMyAdmin - 2.10.2
MySQL client version: 5.0.37
Language: 中文-Chinese simplified
其中,打开了数据库列表显示如下:
数据库 整理
mymy2012 utf8_general_ci
mysql utf8_general_ci
phpmyadmin utf8_bin
test utf8_general_ci
统计: 4 utf8_general_ci
新建php页面时中文显示正常,插入记录集导航条和记录集导航数据时的文字是英文,当运行预览(F12)时,IE页面出现的中文乱码,英文能正常显示;
当从php页面提交插入记录并返回页面时,显示的提交内容没有乱码,只是在Dreamweaver制作时写入的中文是乱码;
然后打开http://localhost/phpmyadmin/页面查看数据库,发现刚才输入的中文显示为乱码;
这个时候,我在数据库里修改刚才输入的中文并保存,这时数据库能显示的是中文,但回到在php页面运行预览(F12)时,在数据库里修改的那部分出现的是很多问号(?),其他没有修改的内容没有变化。请各位高手出手相助!该如何修改才不会乱码?
展开全部
这就是乱码了啊,页面与数据库的编码没有统一起来,一般数据库支持中文肯定是GB2312或者UTF8,你可以在执行插入前,先写上mysql_query("set names utf8")或者mysql_query("set names gb2312");试一下。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
因为编辑器默认是UTF-8,但是汉字属于gb2312或gbk,所以当以输入为汉字的时候需要转换一下,下边是我写的一个转换的类
import java.io.UnsupportedEncodingException;
public class ToNewString {
public static String toNewS(String a){
String b=null;
try {
b= new String(a.getBytes("iso-8859-1"),"gb2312");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return b;
}
}
上面就是将汉字a转换为gb2312的b,你可以直接调用String b="张三" String a=ToNewString.toNewS(b);
import java.io.UnsupportedEncodingException;
public class ToNewString {
public static String toNewS(String a){
String b=null;
try {
b= new String(a.getBytes("iso-8859-1"),"gb2312");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return b;
}
}
上面就是将汉字a转换为gb2312的b,你可以直接调用String b="张三" String a=ToNewString.toNewS(b);
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你用的是黑屏白字的数据库吧?
在里面写一句话:set names gbk;
在里面写一句话:set names gbk;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询