作者:野草 日期:2007年1月19日
前一段发现很多闪友发贴求助flash与数据库连接,所以我研究了了一下,决定给大家写下关于ASP\php\JSp的数据库连接的方法,今天给大家的flash与数据库连接(ASP篇),以后我会陆续为大家奉上,希望大家经常来我的博客做客!一共需要建立三个文件(如图二)。首先写asp文件,起名为save.asp.具体代码如下:
<%
u_name=Request.Form("Name")
u_company=Request.Form("Company")
u_relation=Request.Form("Relation")
u_url=Request.Form("Url")
u_msg=Request.Form("Msg")
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Driver={Microsoft Access Driver (*.mdb)};DBQ=" & server.mappath("Msg.mdb")
sql="Insert into data (Name,Company,Relation,Url,Msg) values (’"&U_name&"’,’"&u_company&"’,’"&u_relation&"’,’"&u_url&"’,’"&u_msg&"’)"
conn.Execute(sql)
conn.close
Set conn=Nothing
Response.Write "&temp=ok"
%>
下面我们做access文件,起名为Msg.mdb!建立表,起名为data表.建立字段名称: id; Name; Company; Relation; Url; Msg; Time. 数据类型依次设定为:自动编号;文本;文本;文本;文本;备注;日期/时间. 保存关闭.最后我们做flash,文件名我起个conn吧!在工作区,照图一去做,每个元件一层!新建最顶层在最后一贞加上如下代码:
System.useCodepage = true;
Name = "";
Company = "";
Relation = "";
Url = "";
Msg = "";
function SendData() {
if (Name != "" && Company != "" && Relation != "" && Msg != "") {
var MyVar = new LoadVars();
MyVar.Name = Name;
MyVar.Company = Company;
MyVar.Relation = Relation;
MyVar.Url = Url;
MyVar.Msg = Msg;
MyVar.sendAndLoad("http://localhost/6/save.asp", MyVar, "POST");
temp = "提交中,請稍侯...";
MyVar.onLoad = function(success) {
if (success) {
temp = "呵呵!成功咯哟!來!再來一條...";
Name = "";
Company = "";
Relation = "";
Url = "";
Msg = "";
} else {
temp = "失敗了!可能網絡有問題!";
}
};
} else {
temp = "請輸入完整!";
}
}
sendBTU.onRelease = function() {
SendData();
};
clearBTU.onRelease = function() {
temp = "歡迎你給我發留言!";
Name = "";
Company = "";
Relation = "";
Url = "";
Msg = "";
};
stop();
然后把相应的输入文本筐的变量起相应的名字!如姓名后面的输入文本筐的变量起名为:Name. 如有什么问题请在下面留言,我会尽快帮你解决!
附件:
图一
图二