PDA

View Full Version : how to deal with the checkbox in asp?



SBUH
September 5th, 2003, 02:58 AM
hello. My situation is that I want to update the database table for the checkbox input with value "1" if the user tick the checkbox.

The value can be sent to the database, but it cannot specify the certain row for updating. Each time when I click the checkbox in row1, all the rows's checkbox column is updated with the value 1. How should I modify so that it only update the rs("ID") 's row checkbox then?

Thanks in advance and wait for reply!!

administrator_ky.asp


------------------------------------------------
<form name="confirm" method="post" action="administrator_ky.asp">

<% Dim rs,conn
Set conn=Server.createObject("ADODB.Connection")
conn.open "Project"

set rs=Server.CreateObject("ADODB.recordset")
sql="select * from Tshirtproduct "
rs.Open sql,Conn
do until rs.EOF

%>
<table>
<tr>
<td><div align="center"><font color="#00CCFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">
<%response.write(rs("logotype"))%>
</font></div></td>
<td><div align="center"><font color="#00CCFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">
&euro;
<%response.write(rs("totalprice"))%>
</font></div></td>

<td><div align="center"><font color="#00CCFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">
<input name="kymitex" type="checkbox" value="1"
<% conn.execute "update Tshirtproduct set kymitex='"& kymitex &"'" ---when we click the first checkbox, all the
------------ rows' checkbox updated with value 1 in the database table!!!!!
If rs("kymitex")="1" then
Response.write("Checked")
end if
%> >
</font></div></td>

<%rs.MoveNext%>
</tr>
<%loop
rs.close


conn.close
%>

</table>
</form>

abzoid
September 5th, 2003, 09:19 AM
You must specify which row entry to update by specifying a unique field such as an autonumbered ID field. Your SQL command would then look something like this:
update Tshirtproduct set kymitex='kymitex ' where ID=rownum

SBUH
September 6th, 2003, 05:10 AM
Thanks for your reply. But my problem is that I cannot know beforehand which column the user may tick. So it should work like when the user tick the third column, the third row is updated with "1". And if the user tick the 10th row, then the 10th row is updataed.

I don't know in this case what should I add in where for updating the table. Do u have any idea?


Thanks in advance!

abzoid
September 6th, 2003, 08:30 AM
If you can't specify a unique value as the WHERE field value in your SQL statement then there is no way to ensure that you will be updating only that one row of your table. It could be an SKU number for that shirt, doesn't matter what it is so long as it is unique within that field of the table.

You may need to either redesign the table to include a unique key field, OR redesign how you are doing this page so that your recordset only has one entry.