之前用DW做留言板.通信录都没问题..但做以下例子就出现insert into 语法错误..
例子演示为:
www1.e7to.com/achou/bl/insert.asp源码为:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/achou.asp" -->
<%
' *** Edit Operations: declare variables
Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd
Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId
Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If
' boolean to abort record edit
MM_abortEdit = false
' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables
If (CStr(Request("MM_insert")) = "form1") Then
MM_editConnection = MM_achou_STRING
MM_editTable = "main"
MM_editRedirectUrl = "insert.asp"
MM_fieldsStr = "user|value|sex|value|tel|value|age|value|mail|value|tec|value|add|value|cen|value|case|value"
MM_columnsStr = "user|',none,''|sex|',none,''|tel|',none,''|age|',none,''|mail|',none,''|tec|',none,''|add|',none,''|cen|',none,''|case|',none,''"
' create the MM_fields and MM_columns arrays
MM_fields = Split(MM_fieldsStr, "|")
MM_columns = Split(MM_columnsStr, "|")
' set the form values
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
Next
' append the query string to the redirect URL
If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it
Dim MM_tablevalues
Dim MM_dbvalues
If (CStr(Request("MM_insert")) <> "") Then
' create the sql insert statement
MM_tablevalues = ""
MM_dbvalues = ""
For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
MM_formVal = MM_fields(MM_i+1)
MM_typeArray = Split(MM_columns(MM_i+1),",")
MM_delim = MM_typeArray(0)
If (MM_delim = "none") Then MM_delim = ""
MM_altVal = MM_typeArray(1)
If (MM_altVal = "none") Then MM_altVal = ""
MM_emptyVal = MM_typeArray(2)
If (MM_emptyVal = "none") Then MM_emptyVal = ""
If (MM_formVal = "") Then
MM_formVal = MM_emptyVal
Else
If (MM_altVal <> "") Then
MM_formVal = MM_altVal
ElseIf (MM_delim = "'") Then ' escape quotes
MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
Else
MM_formVal = MM_delim + MM_formVal + MM_delim
End If
End If
If (MM_i <> LBound(MM_fields)) Then
MM_tablevalues = MM_tablevalues & ","
MM_dbvalues = MM_dbvalues & ","
End If
MM_tablevalues = MM_tablevalues & MM_columns(MM_i)
MM_dbvalues = MM_dbvalues & MM_formVal
Next
MM_editQuery = "insert into " & MM_editTable & " (" & MM_tablevalues & ") values (" & MM_dbvalues & ")"
If (Not MM_abortEdit) Then
' execute the insert
Set 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 <> "") Then
Response.Redirect(MM_editRedirectUrl)
End If
End If
End If
%>
<%
Dim sex
Dim sex_numRows
Set sex = Server.CreateObject("ADODB.Recordset")
sex.ActiveConnection = MM_achou_STRING
sex.Source = "SELECT sex FROM sex ORDER BY ID DESC"
sex.CursorType = 0
sex.CursorLocation = 2
sex.LockType = 1
sex.Open()
sex_numRows = 0
%>
<%
Dim main
Dim main_numRows
Set main = Server.CreateObject("ADODB.Recordset")
main.ActiveConnection = MM_achou_STRING
main.Source = "SELECT * FROM main"
main.CursorType = 0
main.CursorLocation = 2
main.LockType = 1
main.Open()
main_numRows = 0
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>插入</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="css/achou.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style1 {
font-size: 10pt;
font-family: Courier New, Courier, mono;
}
-->
</style>
</head>
<body>
<div align="center">
<form name="form1" method="POST" action="<%=MM_editAction%>">
<table width="500" height="327" border="0" cellspacing="1" bgcolor="#CCCCCC">
<tr bgcolor="#FFFFFF">
<td colspan="4"><div align="center">病历填写</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="114"><div align="center">姓名</div></td>
<td width="208"><div align="center">
<input name="user" type="text" id="user">
</div></td>
<td width="110"><div align="center">性别</div></td>
<td width="160"><div align="left">
<select name="sex" id="sex">
<%
While (NOT sex.EOF)
%>
<option value="<%=(sex.Fields.Item("sex").value)%>" <%If (Not isNull((sex.Fields.Item("sex").value))) Then If (CStr(sex.Fields.Item("sex").value) = CStr((sex.Fields.Item("sex").value))) Then Response.Write("SELECTED") : Response.Write("")%> ><%=(sex.Fields.Item("sex").value)%></option>
<%
sex.MoveNext()
Wend
If (sex.CursorType > 0) Then
sex.MoveFirst
Else
sex.Requery
End If
%>
</select>
</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="114"><div align="center">电话</div></td>
<td><div align="center">
<input name="tel" type="text" id="tel">
</div></td>
<td><div align="center">年龄</div></td>
<td><div align="left">
<input name="age" type="text" id="age" size="3">
</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="114"><div align="center">邮箱</div></td>
<td><div align="center">
<input name="mail" type="text" id="mail">
</div></td>
<td><div align="center">学历</div></td>
<td><div align="left">
<input name="tec" type="text" id="tec" size="10">
</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td><div align="center">地址</div></td>
<td><div align="center">
<input name="add" type="text" id="add">
</div></td>
<td><div align="center">国家</div></td>
<td><div align="left">
<input name="cen" type="text" id="cen" size="10">
</div></td>
</tr>
<tr bgcolor="#FFFFFF">
<td height="153"><div align="center">病历
</div> <div align="center"></div></td>
<td colspan="3"><div align="center">
<textarea name="case" cols="50" rows="8" id="case"></textarea>
</div></td>
</tr>
</table>
<p>
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="恢复">
<input type="hidden" name="MM_insert" value="form1">
</p>
</form>
<p> </p>
</div>
</body>
</html>
<%
sex.Close()
Set sex = Nothing
%>
<%
main.Close()
Set main = Nothing
%>
错误提示:
HTTP 错误 500.100 - 内部服务器错误 - ASP 错误
Internet 信息服务
--------------------------------------------------------------------------------
技术信息(用于支持人员)
错误类型:
Microsoft JET Database Engine (0x80040E14)
INSERT INTO 语句的语法错误。
/blsys/insert.asp, 第 115 行