ADO向表中添加记录只添加一个值

时间:2013-10-11 08:48:32

标签: asp-classic ado

所以我使用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>

它正在工作,但只是将firstname的值添加到表中,而不是lastname,我不知道我哪里出错了,任何帮助人员?

1 个答案:

答案 0 :(得分:2)

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

你错过了一个等号。