I need to retrieve product info. from database and now want to edit some data and save it back to database. I’ve created Edit Form page and passed value to the other Save page. What I want is only to save record that had been edited however when i clicked “save” button, data of all records were passed through. What i confused was with the same passing method, I can successfully delete only specific record.
Here’s my code..
<table cellpadding="0" cellspacing="0" border="1" width="100%">
<tr class="border bluebackend" >
<td class="center bold" width="30">Size</td>
<td class="center bold" width="30">Color</td>
<td class="center bold" width="27%">Est. Qty (dz.)</td>
<td class="center bold" width="30"> </td>
<td class="center bold" width="30"> </td>
</tr>
<%
dim total_qty_est, total_qty
if rsPdtn_sizeColor.eof then
response.Write "<tr><td colspan=""3"">file not found</td></tr>"
Else
Do while Not rsPdtn_sizeColor.EOF
total_qty_est = rsPdtn_sizeColor.fields.item("pdtn_st_qty_est")
total_qty = total_qty + total_qty_est
%>
<tr >
<td class="center">
<select name="pdtn_st_size">
<option selected>-- size -- </option>
<option value="L" <%=checkSelectedScript(rsPdtn_sizeColor.fields.item("pdtn_st_size"),"L")%>>L</option>
<option value="XL" <%=checkSelectedScript(rsPdtn_sizeColor.fields.item("pdtn_st_size"),"XL")%>>XL</option>
</select>
</td>
<td class="center">
<select name="pdtn_st_color">
<option selected>-- color -- </option>
<option value="Orange" <%=checkSelectedScript(rsPdtn_sizeColor.fields.item("pdtn_st_color"),"Orange")%>>Orange</option>
<option value="Pink" <%=checkSelectedScript(rsPdtn_sizeColor.fields.item("pdtn_st_color"),"Pink")%>>Pink</option>
</select>
</td>
<td class="center">
<input type="text" value="<%=PcsToDz(rsPdtn_sizeColor.fields.item("pdtn_st_qty_est"))%>" name="pdtn_st_qty_est" size="3">
(<%=rsPdtn_sizeColor.fields.item("pdtn_st_qty_est")%>)
</td>
<td><input type="button" name="" value="Del" onClick="confirmationDeletePrice('../engine/delPdtn_szCl.asp?pdtn_szcl_id= <%=rsPdtn_sizeColor.fields.item("pdtn_szcl_id")%>&pdtn_st_id=<%=rsPdtn_sizeColor.fields.item("tbl_pdtn_sizecolor.pdtn_st_id")%>')"></td>
<td class="center" >
<input type="button" name="" value="Save" onClick="confirmationSaveProduction_Szcl('production_szcl_edit_action.asp?pdtn_szcl_id= <%=rsPdtn_sizeColor.fields.item("pdtn_szcl_id")%>')">
<input type="hidden" value="Y" name="edit_pdtn_szcl">
<input type="hidden" value="<%=rsPdtn_sizeColor.fields.item("pdtn_szcl_id")%>" name="pdtn_szcl_id">
</td>
</tr>
<%
rsPdtn_sizeColor.movenext
Loop
rsPdtn_sizeColor.movefirst
end if
%>
and this is my Save page code…
<%
pdtn_st_id = Request.form("pdtn_st_id")
pdtn_st_qty_est_dz = Request.form("pdtn_st_qty_est")
if pdtn_st_qty_est_dz <> "" then
pdtn_st_qty_est = DztoPcs(pdtn_st_qty_est_dz)
end if
pdtn_st_size = Request.form("pdtn_st_size")
pdtn_st_color = Request.form("pdtn_st_color")
edit_pdtn_szcl = Request.form("edit_pdtn_szcl")
call checkBlank(pdtn_st_qty_est)
if SomethingError <> "yes" then
Call DBConnOpen()
Set Rs = Server.CreateObject("ADODB.Recordset")
Set Rs.ActiveConnection = Conn
strSQL = "SELECT * FROM tbl_pdtn_sizecolor"
pdtn_szcl_id = Request.form("pdtn_szcl_id")
strSQL = strSQL & " WHERE pdtn_szcl_id =" & pdtn_szcl_id & ""
Rs.Open strSQL, Conn, 1, 3
Rs.Fields("pdtn_st_id") = pdtn_st_id
Rs.Fields("pdtn_st_qty_est") = pdtn_st_qty_est
Rs.Fields("pdtn_st_size") = pdtn_st_size
Rs.Fields("pdtn_st_color") = pdtn_st_color
Rs.Update
Rs.Close
response.redirect "production_view.asp?pdtn_st_id=" & pdtn_st_id
Call DBConnClose()
else
call writeInputError
end if
%>
The simplest solution is to move your existing tags to around the table row in the loop. That way you will be able to edit one row at a time without modifying your save page code.
I have added the form tags to your code below, but you would need to use the FORM tag you are already using: