Home > Backend Development > PHP Tutorial > 用php插入数据只可以插入数字和字母插入不了文字解决方法

用php插入数据只可以插入数字和字母插入不了文字解决方法

WBOY
Release: 2016-06-13 13:38:47
Original
1228 people have browsed it

用php插入数据只可以插入数字和字母插入不了文字
我先用$_POST获取了表单的两个数据然后提交给执行sql语句的页面但是总是一直插入不了文字
+++++++++++++++++++++++++++++++++++++++++++++++++++++
   require "777.php";
 mysql_query("set names 'utf-8");
 mysql_query("SET NAMES 'GB2312'");
  $sql= mysql_query("select*from lyb"); //输出留言内容

  while( $sq = mysql_fetch_array($sql)){

  echo $sq[id];
  }

?>
=++++++++++++++++++++++++++++++++++++++++++++++++++++++


/*
 * Created on 2012-4-3
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 require "777.php";
 if($_POST[submit]!=""){

$user =$_POST[user];
$post = $_POST["intro"];

 $sql = "insert into lyb(user,post) values ('$user','$post')"; //执行sql插入语句页面

$qu= mysql_query($sql);
if($qu){
echo '查看留言' ;


}


  }
?>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

$db ="localhost";
$user="root";
$pwd = "123456";
$conn = mysql_connect("$db","$user","$pwd");
mysql_select_db("sjk",$conn);




?>


++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++











------解决方案--------------------
你的第一段代码有输出吗?都能看到什么?
 mysql_query("set names 'utf-8");
应为
 mysql_query("set names 'utf8");

如果你的程序文件是 utf-8 编码的,用
 mysql_query("set names 'utf8");
如果你的程序文件是 gbk 编码的,用
 mysql_query("SET NAMES 'GB2312'");
最好是
 mysql_query("SET NAMES 'GBK'");

两者选一

第二段代码没有语言声明,即便插入了,也可能是乱码
$sql = "insert into lyb(user,post) values ('$user','$post')";
$qu= mysql_query($sql) or die(mysql_error());
看一下都报什么错

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