用php插入数据只可以插入数字和字母插入不了文字解决方法
程序员文章站
2022-04-25 21:21:25
...
用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());
看一下都报什么错
我先用$_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());
看一下都报什么错
相关文章
相关视频
下一篇: Java中枚举使用方法介绍