标题:ASP新手求助!
只看楼主
tnyu
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-4-12
 问题点数:0 回复次数:9 
ASP新手求助!

我用Dreamweaver表单向导制作好了一个表单,但是我希望按“提交”按妞后转到另一个thankyou.asp的页面,我是ASP新手,请大家教教我应该怎么改代码,谢谢。

表单add.aspthankyou.asp页面在customer文件夹。add.asp具体代码如下:

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="936"%>

<!--#include file="../Connections/customer.asp" -->

<%

// *** Edit Operations: declare variables

// set the form action variable

var MM_editAction = Request.ServerVariables("SCRIPT_NAME");

if (Request.QueryString) {

MM_editAction += "?" + Server.HTMLEncode(Request.QueryString);

}

// boolean to abort record edit

var MM_abortEdit = false;

// query string to execute

var MM_editQuery = "";

%>

<%

// *** Insert Record: set variables

if (String(Request("MM_insert")) == "form1") {

var MM_editConnection = MM_customer_STRING;

var MM_editTable = "客户信息";

var MM_editRedirectUrl = "";

var MM_fieldsStr = "Element3|value|Element4|value|Element5|value|Email|value";

var MM_columnsStr = "姓名|',none,''|固定电话|',none,''|移动电话|',none,''|Email|',none,''";

// create the MM_fields and MM_columns arrays

var MM_fields = MM_fieldsStr.split("|");

var MM_columns = MM_columnsStr.split("|");

// set the form values

for (var i=0; i+1 < MM_fields.length; i+=2) {

MM_fields[i+1] = String(Request.Form(MM_fields[i]));

}

// append the query string to the redirect URL

if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {

MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + Request.QueryString;

}

}

%>

<%

// *** Insert Record: construct a sql insert statement and execute it

if (String(Request("MM_insert")) != "undefined") {

// create the sql insert statement

var MM_tableValues = "", MM_dbValues = "";

for (var i=0; i+1 < MM_fields.length; i+=2) {

var formVal = MM_fields[i+1];

var MM_typesArray = MM_columns[i+1].split(",");

var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";

var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";

var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";

if (formVal == "" || formVal == "undefined") {

formVal = emptyVal;

} else {

if (altVal != "") {

formVal = altVal;

} else if (delim == "'") { // escape quotes

formVal = "'" + formVal.replace(/'/g,"''") + "'";

} else {

formVal = delim + formVal + delim;

}

}

MM_tableValues += ((i != 0) ? "," : "") + MM_columns[i];

MM_dbValues += ((i != 0) ? "," : "") + formVal;

}

MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + ") values (" + MM_dbValues + ")";

if (!MM_abortEdit) {

// execute the insert

var MM_editCmd = Server.CreateObject('ADODB.Command');

MM_editCmd.ActiveConnection = MM_editConnection;

MM_editCmd.CommandText = MM_editQuery;

MM_editCmd.Execute();

MM_editCmd.ActiveConnection.Close();

if (MM_editRedirectUrl) {

Response.Redirect(MM_editRedirectUrl);

}

}

}

%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<title>无标题文档</title>

</head>

<body>

<form method="post" action="<%=MM_editAction%>" name="form1">

<table align="center">

<tr valign="baseline">

<td nowrap align="right">姓名:</td>

<td><input type="text" name="Element3" value="" size="32">

</td>

</tr>

<tr valign="baseline">

<td nowrap align="right">固定电话:</td>

<td><input type="text" name="Element4" value="" size="32">

</td>

</tr>

<tr valign="baseline">

<td nowrap align="right">移动电话:</td>

<td><input type="text" name="Element5" value="" size="32">

</td>

</tr>

<tr valign="baseline">

<td nowrap align="right">Email:</td>

<td><input type="text" name="Email" value="" size="32">

</td>

</tr>

<tr valign="baseline">

<td nowrap align="right">&nbsp;</td>

<td><input name="提交" type="submit" value="插入记录">

<input type="reset" value="重新输入" name="submitButtonName" /> </td>

</tr>

</table>

<input type="hidden" name="MM_insert" value="form1">

</form>

<p>&nbsp;</p>

</body>

</html>

搜索更多相关主题的帖子: ASP 
2006-04-12 11:48
islet
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:89
帖 子:6548
专家分:0
注 册:2005-1-28
得分:0 
MM_editAction += "thankyou.asp?" + Server.HTMLEncode(Request.QueryString);
2006-04-12 11:57
tnyu
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-4-12
得分:0 

不行哦,按你说修改后,提交出现错误。地址栏显示 http://localhost/customer/add.aspthankyou.asp

2006-04-12 12:15
tnyu
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-4-12
得分:0 
不行哦,按你说修改后,提交出现错误。地址栏显示 http://localhost/customer/add.aspthankyou.asp
2006-04-12 12:20
islet
Rank: 12Rank: 12Rank: 12
等 级:贵宾
威 望:89
帖 子:6548
专家分:0
注 册:2005-1-28
得分:0 

<form method="post" action="thankyou.asp" name="form1">

2006-04-12 13:15
xiaona
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2006-4-12
得分:0 
tnyu请教你表单里面的判断怎么弄?

办要精神不滑坡,办法总比困难多
2006-04-12 13:31
tnyu
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-4-12
得分:0 
把 <form method="post" action="<%=MM_editAction%>" name="form1">
改成 <form method="post" action="thankyou.asp" name="form1">
点提交可以转到thankyou.asp页面,但是提交的数据提交不到数据库了,数据库没新数据显示啊
2006-04-12 13:34
xiaona
Rank: 1
等 级:新手上路
帖 子:44
专家分:0
注 册:2006-4-12
得分:0 

因为你没有连接数据库


办要精神不滑坡,办法总比困难多
2006-04-12 13:37
tnyu
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-4-12
得分:0 
连接数据库了啊,如果是<form method="post" action="<%=MM_editAction%>" name="form1"> 那就可以提交数据到数据库但是提交后不能转换到thankyou.asp的页面
如果改成<form method="post" action="thankyou.asp" name="form1"> 提交后可以转换到thankyou.asp页面了但却无法提交数据到数据库.
这该怎么办啊
2006-04-12 14:24
atozxp
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-4-9
得分:0 
在提交完成后加一条response.redirect("thankyou.asp")行不?
我也是新手
2006-04-13 11:14



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-56970-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.150020 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved