Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to update the content of radio buttons in a database?

Status
Not open for further replies.

leifoet

Technical User
Jan 31, 2016
206
BE
I am trying to update (save) the contents of radio buttons to an access database table.
For this I use this w3-e example Link
I linked a SQL update query to it.

Code:
...
<input type="submit" value="Submit" />
</form>
<%
if cars<>"" then
   Response.Write("<p>Your favorite car is: " & cars & "</p>")
end if

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("database.mdb")
Set rs = Server.CreateObject("ADODB.Recordset")

SQL = "UPDATE Form99 "&_
"SET D_A ="&cars&", D_B ="&cars&", D_C ="&cars&", "&_
"S_A ="&cars&", S_B="&cars&", S_C="&cars&", DT = now() WHERE no=99"

rs.Open SQL, Conn
%>

In the w3 example response.write & cars & displays the content (e.g. Saab), but & cars & fails in the database => get this error message

Your favorite car is: Saab
Microsoft OLE DB Provider for ODBC Drivers error '80040e10'
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

Thanks for tips on how to fix this.
 
Looks like cars is a string, so needs some delimiters, and now() is a VBScript variable (looks to me) so it needs to expand.
So this should help:

Code:
QL = "UPDATE Form99 "&_
"SET D_A ='"&cars&"', D_B ='"&cars&"', D_C ='"&cars&"', "&_
"S_A ='"&cars&"', S_B='"&cars&"', S_C='"&cars&"', DT = "& now() &" WHERE no=99"

These days, life being what it is, you should probably be either parameterising the cars variable or at least making it SQL injection safe otherwise it might come to your page
as "saab;delete all from tblUsers;update tblUsers set password='';" or some such

Regards

Griff
Keep [Smile]ing

There are 10 kinds of people in the world, those who understand binary and those who don't.

I'm trying to cut down on the use of shrieks (exclamation marks), I'm told they are !good for you.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top