<form name="myform" method="post" action="customer/tomer.php?act=add">form 跨域提交 编码不同
我把提交的表单放在编码为gb2312的网页中
但提交的目标站点的编码是utf-8的
当表单提交的时候 数字和英文 是正常的,但中文就空的了(没有内容输出 为空状态)
并且我测试了,把提交表单的页面的编码改为utf-8时,完全正常。(很可惜哦,我必须在gb2312的网页中实现)
所以在此向大侠们请教了我知道要用到iconv函数的实现,可是我不懂,帮忙啊!谢谢了
<?php
session_start();
//require_once "../session.php";
require_once '../inc/const.php';
$act = $_GET['act'];
$id =getvar('id');
//$str = iconv('gb2312', 'utf-8', $_POST['name']);
//$str = iconv('gb2312', 'utf-8', $_POST['fax']);
//$str = iconv('gb2312', 'utf-8', $_POST['industry']);
$name =getvar('name');
$addr =getvar('addr');
$httpurl =getvar('httpurl');
$tel =getvar('tel');
$mobile =getvar('mobile');
$fax =getvar('fax');
$email =getvar('email');
$qq =getvar('qq');
$area =getvar('area');
$industry =getvar('industry');
$rank =getvar("rank");$temp_fwnr = "";
$fwnr = $_POST['fwnr'];
for($i=0;$i<count($fwnr);$i++){
$service_start = "service_start".$fwnr[$i];
$service_end = "service_end".$fwnr[$i];
$service_content = "service_content".$fwnr[$i];
//echo $service_start."<br>";
//echo $service_end."<br>";
$temp_services = $fwnr[$i].",".$_POST[$service_start].",".$_POST[$service_end].",".$_POST[$service_content];
$temp_fwnr = empty($temp_fwnr) ? $temp_services : $temp_fwnr."|".$temp_services;
}
if($act=='add'){
$record = array(
'name' =>$name,
'addr' =>$addr,
'httpurl' =>$httpurl,
'tel' =>$tel,
'mobile' =>$mobile,
'fax' =>$fax,
'email' =>$email,
'qq' =>$qq,
'area' =>$area,
'industry' =>$industry,
'services' =>$temp_fwnr,
'rank' =>$rank,
'dateline' =>date("y-m-d H-i-s")
);
$id = $db->insert($GLOBALS[databasePrefix].'customer',$record);
echo "<script>alert('添加成功!');window.location='list.php';</script>";
}
?>用
$str = iconv('gb2312', 'utf-8', $_POST['name']);
echo $str;
进行测试时,能正常的输出中文字
我把提交的表单放在编码为gb2312的网页中
但提交的目标站点的编码是utf-8的
当表单提交的时候 数字和英文 是正常的,但中文就空的了(没有内容输出 为空状态)
并且我测试了,把提交表单的页面的编码改为utf-8时,完全正常。(很可惜哦,我必须在gb2312的网页中实现)
所以在此向大侠们请教了我知道要用到iconv函数的实现,可是我不懂,帮忙啊!谢谢了
<?php
session_start();
//require_once "../session.php";
require_once '../inc/const.php';
$act = $_GET['act'];
$id =getvar('id');
//$str = iconv('gb2312', 'utf-8', $_POST['name']);
//$str = iconv('gb2312', 'utf-8', $_POST['fax']);
//$str = iconv('gb2312', 'utf-8', $_POST['industry']);
$name =getvar('name');
$addr =getvar('addr');
$httpurl =getvar('httpurl');
$tel =getvar('tel');
$mobile =getvar('mobile');
$fax =getvar('fax');
$email =getvar('email');
$qq =getvar('qq');
$area =getvar('area');
$industry =getvar('industry');
$rank =getvar("rank");$temp_fwnr = "";
$fwnr = $_POST['fwnr'];
for($i=0;$i<count($fwnr);$i++){
$service_start = "service_start".$fwnr[$i];
$service_end = "service_end".$fwnr[$i];
$service_content = "service_content".$fwnr[$i];
//echo $service_start."<br>";
//echo $service_end."<br>";
$temp_services = $fwnr[$i].",".$_POST[$service_start].",".$_POST[$service_end].",".$_POST[$service_content];
$temp_fwnr = empty($temp_fwnr) ? $temp_services : $temp_fwnr."|".$temp_services;
}
if($act=='add'){
$record = array(
'name' =>$name,
'addr' =>$addr,
'httpurl' =>$httpurl,
'tel' =>$tel,
'mobile' =>$mobile,
'fax' =>$fax,
'email' =>$email,
'qq' =>$qq,
'area' =>$area,
'industry' =>$industry,
'services' =>$temp_fwnr,
'rank' =>$rank,
'dateline' =>date("y-m-d H-i-s")
);
$id = $db->insert($GLOBALS[databasePrefix].'customer',$record);
echo "<script>alert('添加成功!');window.location='list.php';</script>";
}
?>用
$str = iconv('gb2312', 'utf-8', $_POST['name']);
echo $str;
进行测试时,能正常的输出中文字
<?php
session_start();
//require_once "../session.php";
require_once '../inc/const.php';
$act = $_GET['act'];
$id =getvar('id');
//$str = iconv('gb2312', 'utf-8', $_POST['name']);
//$str = iconv('gb2312', 'utf-8', $_POST['fax']);
//$str = iconv('gb2312', 'utf-8', $_POST['industry']);
$name =getvar('name');
$addr =getvar('addr');
$httpurl =getvar('httpurl');
$tel =getvar('tel');
$mobile =getvar('mobile');
$fax =getvar('fax');
$email =getvar('email');
$qq =getvar('qq');
$area =getvar('area');
$industry =getvar('industry');
$rank =getvar("rank");$temp_fwnr = "";
$fwnr = $_POST['fwnr'];
for($i=0;$i<count($fwnr);$i++){//刚刚加的,不能输出的中文,已经输出中文
foreach($_POST as $na=>$v) {
$$na = iconv('gb2312', 'utf-8', $v);
}
//刚刚加的,不能输出的中文,已经输出中文,但下面的 service 出错误了
$service_start = "service_start".$fwnr[$i];
$service_end = "service_end".$fwnr[$i];
$service_content = "service_content".$fwnr[$i];
//echo $service_start."<br>";
//echo $service_end."<br>";
$temp_services = $fwnr[$i].",".$_POST[$service_start].",".$_POST[$service_end].",".$_POST[$service_content];
$temp_fwnr = empty($temp_fwnr) ? $temp_services : $temp_fwnr."|".$temp_services;
}
if($act=='add'){
$record = array(
'name' =>$name,
'addr' =>$addr,
'httpurl' =>$httpurl,
'tel' =>$tel,
'mobile' =>$mobile,
'fax' =>$fax,
'email' =>$email,
'qq' =>$qq,
'area' =>$area,
'industry' =>$industry,
'services' =>$temp_fwnr,
'rank' =>$rank,
'dateline' =>date("y-m-d H-i-s")
);
$id = $db->insert($GLOBALS[databasePrefix].'customer',$record);
echo "<script>alert('添加成功!');window.location='list.php';</script>";
}
?>
代码加进去后出现了以下的错误了You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
...
写在调用getvar前面
该显示的都正常显示出来了错误内容:
Warning:iconv() expects parameter 3 to be string, array given in d:\test\wwwroot\tomer_ok.php on line 38
当前代码如下:<?php
session_start();
//require_once "../session.php";
require_once '../inc/const.php';
//$act = $_GET['act'];
$id =getvar('id');$name =getvar('name');
$addr =getvar('addr');
$httpurl =getvar('httpurl');
$tel =getvar('tel');
$mobile =getvar('mobile');
$fax =getvar('fax');
$email =getvar('email');
$qq =getvar('qq');
$area =getvar('area');
$industry =getvar('industry');
$rank =getvar("rank");//$_POST['name'] = iconv('gb2312', 'utf-8', $_POST['name']);
//$_POST['fax'] = iconv('gb2312', 'utf-8', $_POST['fax']);
//$_POST['industry'] = iconv('gb2312', 'utf-8', $_POST['industry']);$temp_fwnr = "";
$fwnr = $_POST['fwnr'];
for($i=0;$i<count($fwnr);$i++){ $service_start = "service_start".$fwnr[$i];
$service_end = "service_end".$fwnr[$i];
$service_content = "service_content".$fwnr[$i];
//echo $service_start."<br>";
//echo $service_end."<br>";
$temp_services = $fwnr[$i].",".$_POST[$service_start].",".$_POST[$service_end].",".$_POST[$service_content];
$temp_fwnr = empty($temp_fwnr) ? $temp_services : $temp_fwnr."|".$temp_services;
}
foreach($_POST as $na=>$v) {
$$na = iconv('gb2312', 'utf-8', $v);
}
if($act=='add'){
$record = array(
'name' =>$name,
'addr' =>$addr,
'httpurl' =>$httpurl,
'tel' =>$tel,
'mobile' =>$mobile,
'fax' =>$fax,
'email' =>$email,
'qq' =>$qq,
'area' =>$area,
'industry' =>$industry,
'services' =>$temp_fwnr,
'rank' =>$rank,
'dateline' =>date("y-m-d H-i-s")
);
$id = $db->insert($GLOBALS[databasePrefix].'customer',$record);
echo "<script>alert('添加成功!');window.location='customer_list_jhrayy_com.php';</script>";
}
?>
Warning: iconv() expects parameter 3 to be string, array given in E:\renaiguahao.jhfkw.com\wwwroot\customer\customer_ok_jhrayy_com.php on line 38
操作成功代码如下:<?php
session_start();
//require_once "../session.php";
require_once '../inc/const.php';
//$act = $_GET['act'];
$id =getvar('id');$name =getvar('name');
$addr =getvar('addr');
$httpurl =getvar('httpurl');
$tel =getvar('tel');
$mobile =getvar('mobile');
$fax =getvar('fax');
$email =getvar('email');
$qq =getvar('qq');
$area =getvar('area');
$industry =getvar('industry');
$rank =getvar("rank");//$_POST['name'] = iconv('gb2312', 'utf-8', $_POST['name']);
//$_POST['fax'] = iconv('gb2312', 'utf-8', $_POST['fax']);
//$_POST['industry'] = iconv('gb2312', 'utf-8', $_POST['industry']);$temp_fwnr = "";
$fwnr = $_POST['fwnr'];
for($i=0;$i<count($fwnr);$i++){ $service_start = "service_start".$fwnr[$i];
$service_end = "service_end".$fwnr[$i];
$service_content = "service_content".$fwnr[$i];
//echo $service_start."<br>";
//echo $service_end."<br>";
$temp_services = $fwnr[$i].",".$_POST[$service_start].",".$_POST[$service_end].",".$_POST[$service_content];
$temp_fwnr = empty($temp_fwnr) ? $temp_services : $temp_fwnr."|".$temp_services;
}
foreach($_POST as $na=>$v) {
$$na = iconv('gbk', 'utf-8', $v);
}
if($act=='add'){
$record = array(
'name' =>$name,
'addr' =>$addr,
'httpurl' =>$httpurl,
'tel' =>$tel,
'mobile' =>$mobile,
'fax' =>$fax,
'email' =>$email,
'qq' =>$qq,
'area' =>$area,
'industry' =>$industry,
'services' =>$temp_fwnr,
'rank' =>$rank,
'dateline' =>date("y-m-d H-i-s")
);
$id = $db->insert($GLOBALS[databasePrefix].'customer',$record);
//echo "<script>alert('添加成功!');window.location='customer_list_jhrayy_com.php';< /script>";
echo "操作成功";
}
?>
第三个参数要求是字符串,现在的是数组
你可改用我#4的代码
我在//$act = $_GET['act'];的下面插入了$_POST = eval('return ' . iconv('gb2312', 'utf-8', var_export($_POST, true)) . ';');还是一样的呀
$$na = iconv('gbk', 'utf-8', $v);
}
删去了吗?
foreach($_POST as $na=>$v) {
$$na = iconv('gbk', 'utf-8', $v);
}
这个不行的,删掉了这个 只要是中文就是空白的 没有数据显示
$$na = iconv('gbk', 'utf-8', $v);
}
改为:
foreach($_POST as $na=>$v) {
var_dump($v); //看看
//$$na = iconv('gbk', 'utf-8', $v);
}
上面加一个var_dump($v);$v不是一个STRING,必须想法转成STRING!
header("content-type:text/html;charset=utf-8");
我解决了,下面这个代码只是差了一个@
我把
foreach($_POST as $na=>$v) {
$$na = iconv('gbk', 'utf-8', $v);
}
改成
foreach($_POST as $na=>$v) {
@$$na = iconv('gbk', 'utf-8', $v);
}
就OK了谢谢呵呵