请问PHP 将中文 英文提交MYSQL 都不成功只能提交数字 请问如何修改 10
<?header("content-Type:text/html;charset=GB2312");?><?php$conn=mysql_connect("","",""...
<?header("content-Type: text/html; charset=GB2312"); ?>
<?php
$conn = mysql_connect(" "," "," ") or die("数据库连接失败");//连接数据库IP.用户名密码
mysql_select_db(" ",$conn) or die("数据库选择失败");//选择数据库
mysql_query('set names GB2312');//连接数据库文字编码
//连接数据库
//$conn=mysql_connect("sql.w69.vhostgo.com","xbsmh2shunter","xbsm320007") or die("SQL SERVER 数据库连接失败!");
//连接数据库IP.用户名密码
//mysql_select_db("h2shuntermysql",$conn);//选择数据库
//md5加密$pwd = md5($_POST['pwd']);
$x1 =iconv("UTF-8","gb2312",$_POST['x15']);
$x2 =iconv("UTF-8","gb2312",$_POST['x15']);
$x3 =iconv("UTF-8","gb2312",$_POST['x15']);
$x4= iconv("UTF-8","gb2312",$_POST['x15']);
$x5 = iconv("UTF-8","gb2312",$_POST['x15']);
$x6 =iconv("UTF-8","gb2312",$_POST['x15']);
$x7 = iconv("UTF-8","gb2312",$_POST['x15']);
$x8= iconv("UTF-8","gb2312",$_POST['x15']);
$x9 =iconv("UTF-8","gb2312",$_POST['x15']);
$x10 =iconv("UTF-8","gb2312",$_POST['x15']);
$x11= iconv("UTF-8","gb2312",$_POST['x15']);
$x12 = iconv("UTF-8","gb2312",$_POST['x15']);
$x13 =iconv("UTF-8","gb2312",$_POST['x15']);
$x14=iconv("UTF-8","gb2312",$_POST['x15']);
$x15 = iconv("UTF-8","gb2312",$_POST['x15']);
$x16 =iconv("UTF-8","gb2312",$_POST['x16']);
$sql="INSERT INTO bm(bm1, bm2, bm3, bm4, bm5, bm6, bm7, bm8, bm9, bm10, bm11, bm12, bm13, bm14, bm15, bm16) VALUES ($x1,$x2,$x3,$x4,$x5,$x6,$x7,$x8,$x9,$x10,$x11,$x12,$x13,$x14,$x15,$x16)";
mysql_query($sql);
//输出结果
//关闭连接
mysql_close($conn);
?> 展开
<?php
$conn = mysql_connect(" "," "," ") or die("数据库连接失败");//连接数据库IP.用户名密码
mysql_select_db(" ",$conn) or die("数据库选择失败");//选择数据库
mysql_query('set names GB2312');//连接数据库文字编码
//连接数据库
//$conn=mysql_connect("sql.w69.vhostgo.com","xbsmh2shunter","xbsm320007") or die("SQL SERVER 数据库连接失败!");
//连接数据库IP.用户名密码
//mysql_select_db("h2shuntermysql",$conn);//选择数据库
//md5加密$pwd = md5($_POST['pwd']);
$x1 =iconv("UTF-8","gb2312",$_POST['x15']);
$x2 =iconv("UTF-8","gb2312",$_POST['x15']);
$x3 =iconv("UTF-8","gb2312",$_POST['x15']);
$x4= iconv("UTF-8","gb2312",$_POST['x15']);
$x5 = iconv("UTF-8","gb2312",$_POST['x15']);
$x6 =iconv("UTF-8","gb2312",$_POST['x15']);
$x7 = iconv("UTF-8","gb2312",$_POST['x15']);
$x8= iconv("UTF-8","gb2312",$_POST['x15']);
$x9 =iconv("UTF-8","gb2312",$_POST['x15']);
$x10 =iconv("UTF-8","gb2312",$_POST['x15']);
$x11= iconv("UTF-8","gb2312",$_POST['x15']);
$x12 = iconv("UTF-8","gb2312",$_POST['x15']);
$x13 =iconv("UTF-8","gb2312",$_POST['x15']);
$x14=iconv("UTF-8","gb2312",$_POST['x15']);
$x15 = iconv("UTF-8","gb2312",$_POST['x15']);
$x16 =iconv("UTF-8","gb2312",$_POST['x16']);
$sql="INSERT INTO bm(bm1, bm2, bm3, bm4, bm5, bm6, bm7, bm8, bm9, bm10, bm11, bm12, bm13, bm14, bm15, bm16) VALUES ($x1,$x2,$x3,$x4,$x5,$x6,$x7,$x8,$x9,$x10,$x11,$x12,$x13,$x14,$x15,$x16)";
mysql_query($sql);
//输出结果
//关闭连接
mysql_close($conn);
?> 展开
1个回答
2014-11-16
展开全部
无论什么数据库,插入语句都要和数据库结构相互对应
在sql语句中,基本情况下,有2种状态对应2种情况
如果数据库字段是非数字类型的(varchar等类型的字段), 如果插入的是数字,那么,插入的值加不加引号都可以插入, 如果插入的文本值, 那必须加上引号
如果字段类型是数字类型的(int、bigint等类型的字段), 那么插入的值必须是数字类型,而且不能加上引号
而你看一下你的sql语句, VALUES( 这里面的值 ) 全部没有引号
那么,这条语句要成功,要不就是你插入的全部要是数字,要不数据表中所对应的字段全部要是数字类型字段,
你再看看是这样的吗?
在sql语句中,基本情况下,有2种状态对应2种情况
如果数据库字段是非数字类型的(varchar等类型的字段), 如果插入的是数字,那么,插入的值加不加引号都可以插入, 如果插入的文本值, 那必须加上引号
如果字段类型是数字类型的(int、bigint等类型的字段), 那么插入的值必须是数字类型,而且不能加上引号
而你看一下你的sql语句, VALUES( 这里面的值 ) 全部没有引号
那么,这条语句要成功,要不就是你插入的全部要是数字,要不数据表中所对应的字段全部要是数字类型字段,
你再看看是这样的吗?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询