大家看看这个代码ASP无法向数据库添加记录,在线等
<%OptionExplicit%><!--#Includefile="odbc_connection.asp"--><html><head><title>输入结果</t...
<% Option Explicit %>
<!--#Include file="odbc_connection.asp"-->
<html>
<head>
<title>输入结果</title>
</head>
<body>
<%
On Error Resume Next
If Trim(Request("name"))="" Or Trim(Request("password"))=""Then
Response.Write "对不起,姓名和密码必须输入"
Response.Write "<p><a href='add_form.htm'>返回,重新填写</a>"
Else
Dim name,password,tel,email,home,age,intro
name=Request("name")
password=Request("password")
tel=Request("tel")
home=Request("home")
email=Request("email")
age=Request("age")
intro=Request("intro")
'下面将数据填入数据库中
Dim strSql,sqla,sqlb
sqla = "Insert Into users(name,password"
sqlb = "Values('" & name & "','" & password & "'"
If tel<>"" Then
sqla = sqla & ",tel"
sqlb = sqlb & ",'" & tel & "'"
End If
If home<>"" Then
sqla = sqla & ",home"
sqlb = sqlb & ",'" & home & "'"
End If
If email<>"" Then
sqla = sqla & ",email"
sqlb = sqlb & ",'" & email & "'"
End If
If age<>"" Then
sqla = sqla & ",age"
sqlb = sqlb & "," & cInt(age) 'age是数字类型,请注意添加方法。
End If
If intro<>"" Then
sqla = sqla & ",intro"
sqlb = sqlb & ",'" & intro & "'"
End If
strSql = sqla & ") " & sqlb & ")"
db.Execute(strSql) '执行添加操作
'下面判断插入过程有无错误,并给出相应信息
If db.Errors.Count<0 Then
Response.Write "保存过程中发生错误,必须重新填写"
Response.Write "<p><a href='add_form.htm'>返回,重新填写</a>"
Else
Response.Write "<h2 align='center'>您的信息已经安全加入,请牢记密码</h2>"
Response.Write "<p>姓名:" & name
Response.Write "<p>电话:" & tel
Response.Write "<p>email:" & email
Response.Write "<p>住址:" & home
Response.Write "<p>年龄:" & age
Response.Write "<p>简介:" & intro
Response.Write "<p><a href='add_form.htm'>返回,继续添加</a>"
End If
End If
%>
</body>
</html> 展开
<!--#Include file="odbc_connection.asp"-->
<html>
<head>
<title>输入结果</title>
</head>
<body>
<%
On Error Resume Next
If Trim(Request("name"))="" Or Trim(Request("password"))=""Then
Response.Write "对不起,姓名和密码必须输入"
Response.Write "<p><a href='add_form.htm'>返回,重新填写</a>"
Else
Dim name,password,tel,email,home,age,intro
name=Request("name")
password=Request("password")
tel=Request("tel")
home=Request("home")
email=Request("email")
age=Request("age")
intro=Request("intro")
'下面将数据填入数据库中
Dim strSql,sqla,sqlb
sqla = "Insert Into users(name,password"
sqlb = "Values('" & name & "','" & password & "'"
If tel<>"" Then
sqla = sqla & ",tel"
sqlb = sqlb & ",'" & tel & "'"
End If
If home<>"" Then
sqla = sqla & ",home"
sqlb = sqlb & ",'" & home & "'"
End If
If email<>"" Then
sqla = sqla & ",email"
sqlb = sqlb & ",'" & email & "'"
End If
If age<>"" Then
sqla = sqla & ",age"
sqlb = sqlb & "," & cInt(age) 'age是数字类型,请注意添加方法。
End If
If intro<>"" Then
sqla = sqla & ",intro"
sqlb = sqlb & ",'" & intro & "'"
End If
strSql = sqla & ") " & sqlb & ")"
db.Execute(strSql) '执行添加操作
'下面判断插入过程有无错误,并给出相应信息
If db.Errors.Count<0 Then
Response.Write "保存过程中发生错误,必须重新填写"
Response.Write "<p><a href='add_form.htm'>返回,重新填写</a>"
Else
Response.Write "<h2 align='center'>您的信息已经安全加入,请牢记密码</h2>"
Response.Write "<p>姓名:" & name
Response.Write "<p>电话:" & tel
Response.Write "<p>email:" & email
Response.Write "<p>住址:" & home
Response.Write "<p>年龄:" & age
Response.Write "<p>简介:" & intro
Response.Write "<p><a href='add_form.htm'>返回,继续添加</a>"
End If
End If
%>
</body>
</html> 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询