2007年3月14日星期三

flash与数据库连接


一共需要建立三个文件。首先写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();

其他的文章

 
©2003-2007 [ 温柔菜刀 ] : Blogger Name 刘斌的博客