Forums

ASP

This topic is locked

update stt- Too few parameters. Expected 1.

Posted 08 Mar 2008 11:47:39
1
has voted
08 Mar 2008 11:47:39 sankari iyer posted:
let me tell u what the code does.
retrieve data ( text box, 2 radio buttons, ) from db.
on selection of any of the radio buttons, the counter should be incremented accordinglt
in the database i have these fields, question, option1,option2,option1_ctr,option2_ctr.
if option1 is clicked, then option1_ctr should be incremented. similarly
if option2 is clicked, then option2_ctr should be incremented.

if I remove the WHERE clause in update st, allt eh rows get updated.


<%
Dim Conn 'Holds the Database Connection Object
Dim RS 'Holds the recordset for the records in the database
Dim mySQL 'Holds the SQL query to query the database
Dim execSQL
Dim ques
Dim opt1
Dim opt2
Dim y_ctr
Dim n_ctr
Dim theform


Set Conn = Server.CreateObject("ADODB.Connection"

Conn.ConnectionString = "DSN=pollz"
Conn.Open


mySQL = "SELECT * FROM pollz"


Set RS = Server.CreateObject("ADODB.Recordset"
RS.Open mySQL, Conn
rs.movefirst
clr=1
'ques=rs("question"
'session("ques"=ques
yes_ctr=rs("option1_ctr"
no_ctr=rs("option2_ctr"
opt1= rs("option1"
opt2 =rs("option2"
response.write "yes" & yes_ctr
response.write "no" & no_ctr
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<SCRIPT language="JavaScript">

function testButton (form){
var y_ctr;
var n_ctr;
var quest;
y_ctr = <% =yes_ctr %>
n_ctr = <% =no_ctr %>
alert(y_ctr)
alert(n_ctr)


if (form.ans[0].checked)
{
alert("inside"
y_ctr=y_ctr+1;
document.array1.hid_code_y.value=y_ctr;
document.array1.hid_code_n.value=n_ctr;

}
else
{
n_ctr=n_ctr+1;
document.array1.hid_code_n.value=n_ctr;
document.array1.hid_code_y.value=y_ctr;
}

document.array1.submit();
}
</script>
</head>

<body>

<form name='array1' method='post' action='post.asp'>

<table valign='top' border=1 align=center width='80%' cellpadding=0 cellspacing=0>
<tr><td width='70%'> <%= rs("question" %></td>
<td width='6%'><input type='radio' onClick='testButton(this.form)' name='ans' value= <%=rs("option1" %>> <%=rs("option1" %></td>
<td width='6%'><input type='radio' onClick='testButton(this.form)' name='ans' value= <%=rs("option2" %>> <%=rs("option2" %></td>
</table>
<input type='hidden' name='hid_code_y'>
<input type='hidden' name='hid_code_n'>
<input type='hidden' name='quess' value= <%= rs("question"%>>
</form>
<%
y_ctr=request.Form("hid_code_y"
n_ctr=request.Form("hid_code_n"
quest=request.Form("quess"
session("ques"=quest
response.write quest

ty=rs(1)
response.write ty
execSQL="update pollz set option1_ctr=" & y_ctr & ",option2_ctr=" & n_ctr & " where question=" & ty

response.write execSQL
Conn.execute(execSQL)
RS.Close
Set RS = Nothing
Set Conn = Nothing

%>


</body>
</html>

Reply to this topic