0

所以我使用 ADO 将数据添加到 sql 数据库中,这是我的原始代码:

<!DOCTYPE html>
<html>
 <body>

     <h1>
      Teacher registration 
      </h1>
      <form name="teacherReg" action="http://hr-computing/public/AlexS/Tests/login.asp" method="POST">
      First name:<input type="text" name="firstname"><br>
      Last name:<input type="text" name"lastname">
      <input type="submit" value="submit">
      </form>
<%
 set conn=Server.CreateObject("ADODB.Connection")
 conn.Open ={ private }
set rs=Server.CreateObject("ADODB.recordset")
rs.Open "Select * from teachers", conn


sql="INSERT INTO teachers (firstname, lastname)"
sql=sql & " VALUES "
sql=sql & "('" & Request.Form("firstname") & "',"
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>

它正在工作,但只将名字的值添加到表中,而不是姓氏,我看不出我哪里出错了,有帮助吗?

4

1 回答 1

2

更改<input type="text" name"lastname"><input type="text" name="lastname">

您缺少一个等号。

于 2013-10-11T09:09:02.187 回答