php 打造注册页面 中文无法存入sql 求解

WBOY
Release: 2016-06-13 11:19:06
Original
801 people have browsed it

php 制作注册页面 中文无法存入sql 求解
用html制作了一个注册页面,提交到php页面,用post方法传送数据,但是文本框中输入了中文无法存入sql数据库中。求解,下面是关键代码:
======================================================================================
$userid=$_POST['userid'];
     $username=$_POST['username'];
      $userpwd=$_POST['userpwd'];
       $userage=$_POST['userage'];
        $usersex=$_POST['usersex'];
$conn=mysql_connect("localhost","root","");

mysql_select_db("newdb",$conn);

$sql="INSERT INTO usersinfo (userid,userpwd,username,userage,usersex)values('$userid','$userpwd','$username','$userage','$usersex')";
 mysql_query("set names 'utf8'");
$query=mysql_query($sql,$conn);
======================================================================================
userid usepwd userage 这三项为数字,可以存入sql数据库中,但是username usersex无法存入,
打开phpmyadmin 查看数据库,发现中文的那几栏都只有一个空格,存进去失败了。
不知道出现什么问题,添加了:
echo $userid."
";
echo $username."
";
echo $userpwd."
";
echo $userage."
";
echo $usersex."
";
发现可以正常输出任何变量,说明不是取值问题,是存入数据库的时候出问题了,我想是不是数据编码的问题..?

php 数据库
------解决方案--------------------
可否把数据库表结构贴出来看看是不是数据库字段类型的问题
------解决方案--------------------
一般是字符编码问题,可能你页面是GB2312数据库是UTF8,你用iconv("gbk","utf-8",$_POST['xx'])转下
------解决方案--------------------


发一个 Ecshop 给你看一下。

另外网页代码编码,也需要用跟数据库一致才行。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!