我在这里遇到了问题。我已经创建了一个用于将记录添加到数据库中的页面,它工作正常但是每次页面加载时都会运行asp脚本,每次加载页面时都会向数据库输入一个空白记录,这非常令人讨厌我有其他脚本。我觉得自己非常愚蠢,但我只需要点击提交按钮后脚本就可以运行了,我该怎么做才能做到这一点?
<!DOCTYPE html>
<html>
<title>
Teacher Registration
</title>
<body>
<h1>
Teacher registration
</h1>
<form name="teacherReg" action="Registration.asp" method="POST">
First name:<input type="text" name="firstname"><br>
Last name:<input type="text" name="lastname"><br>
Password :<input type="password" name="password">
<input type="submit" value="submit">
</form>
<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open ="Driver={SQL Server}; Server=QuizDynamics.db.11989315.hostedresource.com; Database=QuizDynamics; Uid=QuizDynamics; Pwd=Compostheap12!;"
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from teachers", conn
sql="INSERT INTO teachers (firstname, password, lastname)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("firstname") & "',"
sql=sql & "'" & Request.Form("password") & "',"
sql=sql & "'" & Request.Form("lastname") & "')"
on error resume next
conn.Execute sql,recaffected
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>
</body>
</html>
答案 0 :(得分:0)
为您的提交输入提供名称属性 - 例如submitbutton - 然后执行类似
的操作if request.form("submitbutton") <> "" then
'put your insert code here
End if