You have several problems in your script.
- SQL injection! Inform yourself about SQL injection and rewrite your entire script to avoid that! Do it first before you do anything else.
- You are testing if
Request.Form("ID")
is ""
. But in your select you are using it although it is an empty string.
- When using
on error resume next
in classic asp, you have to "switch off" error handling by using on error goto 0
. Otherwise the on error resume next
will be used for the rest of your script.
- What are you trying to achieve by that
refresh
meta tag?
My suggestion to you is the following:
- Read about about SQL injection.
- Try to make a page which just lists the records from
tICTStaff
.
- Then make a second page for editing those records. When you click on the edit button on the first page, navigate to your edit page and load that specific record from
tICTStaff
.
- On your edit page, make a comfortable form and implement the update routine for that specific record.
On your overview site make links like so:
<%
Set oRs = Server.CreateObject("ADODB.Recordset")
oRs.open "SELECT * FROM tICTStaff", Conn
do while not oRS.eof %>
<tr>
<td></td>
<td></td>
<td></td>
<td><a href="update.asp?id=<%=oRS.fields("ID").value%>">link to detail/update page</a></td>
</tr>
<% oRS.movenext
loop %>
on your update.asp page load the record with the id from the querystring and display the form like so:
<%
dim myID : myID = request.querystring("ID")
if myID = "" then myID = request.form("ID")
' update record
if request.form("submit01") = "update" then
sql = "update tICTStaff set fieldName1 = ? WHERE ID = ?"
set cmd = server.createobject("adodb.command")
cmd.activeconnection = Conn
cmd.CommandType = adCmdText
cmd.commandtext = sql
cmd.parameters.append cmd.createparameter("fieldName1", adVarchar, , 512, request.form("fieldName1") )
cmd.parameters.append cmd.createparameter("id", adInteger, , , myID )
set oRS = cmd.execute
end if
' load record
sql = "select * from tICTStaff where id = ?"
set cmd = server.createobject("adodb.command")
cmd.activeconnection = Conn
cmd.CommandType = adCmdText
cmd.commandtext = sql
cmd.parameters.append cmd.createparameter("id", adInteger, , , myID )
set oRS = cmd.execute
' now you have a recordset with the record from tICTStaff with the ID
%>
<!-- display the form -->
<form name="" method="post">
<input type="hidden" name="id" value="<%=myID%>">
<!-- more fields to be edited -->
<input type="text" name="fieldName1" value="<%=oRS.fields("fieldName1").value%>">
<input type="submit" name="submit01" value="update">
</form>
completely different solution (ajax based):
As you want some kind of "mass update" function for the whole table, try jQuery with an AJAX call. So, on click of the button at the end of each row, you send an AJAX request to your ASP site with the values of the input fields and the ID of the record (the primary key of the tICTStaff
table).
On the ASP page, you process the AJAX request and generate an UPDATE statement to update the tICTStaff
table like so:
UPDATE tICTStaff
SET fldname1 = fldVal1, fldname2 = fldVal2
WHERE ID = postedID
To read about jQuery AJAX, have a look here.