用asp向sql2000数据库插入一条新数据,我一进入页面就自动往里插入一条空数据,如何修改。
<body><formmethod="post"action="add.asp"><tableborder="1"width="100%"><tr><tdwidth="3...
<body>
<form method="post" action="add.asp">
<table border="1" width="100%">
<tr>
<td width="30%">序号:</td>
<td width="70%"><input name="nubmer1"></td>
</tr><tr>
<td>ID:</td>
<td><input name="id1"></td>
</tr><tr>
<td>名字:</td>
<td><input name="name1"></td>
</tr><tr>
<td>属性:</td>
<td><input name="shuxing1"></td>
</tr><tr>
</table>
<br /><br />
<input type="submit" value="Add New">
<input type="reset" value="Cancel">
</form>
<p><a href="index.asp">add</a>
<%
dim bumber1
dim id1
dim name1
dim shuxing1
number1=request("number1")
id1=request("id1")
name1=request("name1")
shuxing1=request("shuxing1")
sql="INSERT INTO chanpin (number,id,name,shuxing) VALUES ('"&number1&"','"&id1&"','"&name1&"','"&shuxing1&"')"
conn.execute sql
on error resume next
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>
</body> 展开
<form method="post" action="add.asp">
<table border="1" width="100%">
<tr>
<td width="30%">序号:</td>
<td width="70%"><input name="nubmer1"></td>
</tr><tr>
<td>ID:</td>
<td><input name="id1"></td>
</tr><tr>
<td>名字:</td>
<td><input name="name1"></td>
</tr><tr>
<td>属性:</td>
<td><input name="shuxing1"></td>
</tr><tr>
</table>
<br /><br />
<input type="submit" value="Add New">
<input type="reset" value="Cancel">
</form>
<p><a href="index.asp">add</a>
<%
dim bumber1
dim id1
dim name1
dim shuxing1
number1=request("number1")
id1=request("id1")
name1=request("name1")
shuxing1=request("shuxing1")
sql="INSERT INTO chanpin (number,id,name,shuxing) VALUES ('"&number1&"','"&id1&"','"&name1&"','"&shuxing1&"')"
conn.execute sql
on error resume next
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
%>
</body> 展开
1个回答
展开全部
哈哈!
代码asp 部分因为没有限制,所以一打开这个页面就执行插入。
要改两个地方:
1) <form method="post" action="add.asp"> 改为 <form method="post" action="add.asp?do=yes">
2) <% dim bumber1 这里加上判断,当接收到 do=yes 时才执行这段ASP代码
<%
if request("do")="yes" then '当接收到 do=yes 时才执行这段ASP代码
dim bumber1
dim id1
dim name1
dim shuxing1
number1=request("number1")
id1=request("id1")
name1=request("name1")
shuxing1=request("shuxing1")
sql="INSERT INTO chanpin (number,id,name,shuxing) VALUES ('"&number1&"','"&id1&"','"&name1&"','"&shuxing1&"')"
conn.execute sql
on error resume next
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
end if
%>
代码asp 部分因为没有限制,所以一打开这个页面就执行插入。
要改两个地方:
1) <form method="post" action="add.asp"> 改为 <form method="post" action="add.asp?do=yes">
2) <% dim bumber1 这里加上判断,当接收到 do=yes 时才执行这段ASP代码
<%
if request("do")="yes" then '当接收到 do=yes 时才执行这段ASP代码
dim bumber1
dim id1
dim name1
dim shuxing1
number1=request("number1")
id1=request("id1")
name1=request("name1")
shuxing1=request("shuxing1")
sql="INSERT INTO chanpin (number,id,name,shuxing) VALUES ('"&number1&"','"&id1&"','"&name1&"','"&shuxing1&"')"
conn.execute sql
on error resume next
if err<>0 then
Response.Write("No update permissions!")
else
Response.Write("<h3>" & recaffected & " record added</h3>")
end if
conn.close
end if
%>
更多追问追答
追问
还有一个问题请教,就是我每次插入数据时,numebr也就是数据第一列的数据总是写不上,请指教。
追答
("&number1&",'"&id1&"','"&name1&"','"&shuxing1&"')"
&number1& 两边的单引号去掉
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |