我想把如下的SQL语句当参数传递给另外一个页面。
但是总报错误。请各位帮帮忙!<?php
$sql="insert into customers (cust_id,realname,gender, studet_type,idorgan,idorigin,birthday_year,birthday_month, birthday_day,customer_level,course_level,train_type,customer_ID, account_address,user_address,education,education_school, certification_time,workplace,work_expertise,address,zip, mobile_phone,phone,qq_msn_web,email,regdate,applicants, department,professional,jobs,worktime,business_type,f_time,t_time,s_time ) VALUES( 'C20101230213534','店小二','1', '1','0','2','','', '','B','无','面授','', '','天津','','', '0000-00-00','','','','', '12345678901','','','[email protected]','2010-12-30 21:35:34','133', '','','','','保险', '2011-04-30 23:59:59','2011-04-20 00:00:01', '2011-06-30 23:59:59')";
?>
<script language="javascript">
function InitAjax()
{
var ajax=false;
try
{
ajax=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
ajax=new ActiveXObject("Microsft.XMLHTTP");
}
catch(E)
{
ajax=false;
}
}
if(!ajax&& typeof XMLHttpRequest !='undefined')
{
ajax=new XMLHttpRequest();
}
return ajax;
} function onPostSQL(getSql)
{
//获取表单对象和用户信息值 //接收表单的URL地址
var url="../convert/postSql.php";
//需要POST的值,把每个变量都通过&来联接
var postStr = "getSql="+ getSql;
//实例化Ajax
var ajax = InitAjax();
//通过Post方式打开连接
ajax.open("POST", url, true);
//定义传输的文件HTTP头信息
ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//发送POST数据
//alert(postStr);
ajax.send(postStr);
//获取执行状态
ajax.onreadystatechange = function()
{
//如果执行状态成功,那么就把返回信息写到指定的层里
if (ajax.readyState == 4 && ajax.status == 200)
{
ajax.responseText;
}
}
}
onPostSQL("<?=$getSql?>");
</script>
但是总报错误。请各位帮帮忙!<?php
$sql="insert into customers (cust_id,realname,gender, studet_type,idorgan,idorigin,birthday_year,birthday_month, birthday_day,customer_level,course_level,train_type,customer_ID, account_address,user_address,education,education_school, certification_time,workplace,work_expertise,address,zip, mobile_phone,phone,qq_msn_web,email,regdate,applicants, department,professional,jobs,worktime,business_type,f_time,t_time,s_time ) VALUES( 'C20101230213534','店小二','1', '1','0','2','','', '','B','无','面授','', '','天津','','', '0000-00-00','','','','', '12345678901','','','[email protected]','2010-12-30 21:35:34','133', '','','','','保险', '2011-04-30 23:59:59','2011-04-20 00:00:01', '2011-06-30 23:59:59')";
?>
<script language="javascript">
function InitAjax()
{
var ajax=false;
try
{
ajax=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
ajax=new ActiveXObject("Microsft.XMLHTTP");
}
catch(E)
{
ajax=false;
}
}
if(!ajax&& typeof XMLHttpRequest !='undefined')
{
ajax=new XMLHttpRequest();
}
return ajax;
} function onPostSQL(getSql)
{
//获取表单对象和用户信息值 //接收表单的URL地址
var url="../convert/postSql.php";
//需要POST的值,把每个变量都通过&来联接
var postStr = "getSql="+ getSql;
//实例化Ajax
var ajax = InitAjax();
//通过Post方式打开连接
ajax.open("POST", url, true);
//定义传输的文件HTTP头信息
ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
//发送POST数据
//alert(postStr);
ajax.send(postStr);
//获取执行状态
ajax.onreadystatechange = function()
{
//如果执行状态成功,那么就把返回信息写到指定的层里
if (ajax.readyState == 4 && ajax.status == 200)
{
ajax.responseText;
}
}
}
onPostSQL("<?=$getSql?>");
</script>
$sql="insert into customers (cust_id,realname,gender, studet_type,idorgan,idorigin,birthday_year,birthday_month, birthday_day,customer_level,course_level,train_type,customer_ID, account_address,user_address,education,education_school, certification_time,workplace,work_expertise,address,zip, mobile_phone,phone,qq_msn_web,email,regdate,applicants, department,professional,jobs,worktime,business_type,f_time,t_time,s_time ) VALUES( 'C20101230213534','店小二','1', '1','0','2','','', '','B','无','面授','', '','天津','','', '0000-00-00','','','','', '12345678901','','','[email protected]','2010-12-30 21:35:34','133', '','','','','保险', '2011-04-30 23:59:59','2011-04-20 00:00:01', '2011-06-30 23:59:59')";echo '<script language="javascript">function InitAjax()
{
var ajax=false;
try
{
ajax=new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
ajax=new ActiveXObject("Microsft.XMLHTTP");
}
catch(E)
{
ajax=false;
}
}
if(!ajax&& typeof XMLHttpRequest !="undefined")
{
ajax=new XMLHttpRequest();
}
return ajax;
} function onPostSQL(getSql)
{
alert(getSql);
//获取表单对象和用户信息值 //接收表单的URL地址
var url="../convert/postSql.php";
//需要POST的值,把每个变量都通过&来联接
var postStr = "getSql="+ getSql;
//实例化Ajax
var ajax = InitAjax();
//通过Post方式打开连接
ajax.open("POST", url, true);
//定义传输的文件HTTP头信息
ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
//发送POST数据
//alert(postStr);
ajax.send(postStr);
//获取执行状态
ajax.onreadystatechange = function()
{
//如果执行状态成功,那么就把返回信息写到指定的层里
if (ajax.readyState == 4 && ajax.status == 200)
{
ajax.responseText;
}
}
} onPostSQL("'.$sql.'"); </script> ';?>
if (ajax.readyState == 4 && ajax.status == 200)
{
alert(ajax.responseText;) //改成这样最好能看效果
} 多到GOOGLE找找AJAX资料,很简单
如果是同个网站的,干脆把文件包含一下
不建议传SQL语句。
一般这么用,也可用base64加密一下。
先执行sql语句就好了啊!
不然把sql输出再执行啦!!
把值传过去,php再拼凑成sql语句。
看看源代码中文注释是否乱码导致你的代码混乱
全部过程放在AJAX中
把insert处理为一个执行标识,如:select(oper=1),insert(oper=2),update(oper=3).
另你的字段也要做成数字或字母标识,如:1,2,3,4,5分别代表1-5个字段,或用a-e..
这样构建url时这样:var url=....php?oper=1&datafield=1,2,3,4,5&values=.....
可以做一些加密处理..
你所有的这些数据可以由PHP写入JS中:
echo '<script>var oper=1;...</script>'