[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 171
  • Last Modified:

INSERT statement - values of check boxes data type problem

Hi, I have this INSERT statement below and am not sure how to correct it to insert a checked or unchecked value of a check box.  The check box is name txtage.

session ("strage")=Request.Form ("txtage")

function checkform
If session ("strage")="no" then
 response.redirect "caukus.asp?type=18&msg="&server.urlencode("Please confirm you are 18 or over")
      exit function
End If
End Function
call checkform

SQLINSERT = "INSERT INTO tbl_application(firstname,surname,username,password,mobile,driving_licence,dob,confirm_age,email) values('" & replace(session ("strfirstname"), "'", "")& "','" & replace(session ("strsurrname "), "'", "")& "','" & replace(session ("strusername"), "'", "")& "','" & replace(session ("strpassword"), "'", "")& "','" & replace(session ("strmob"), "'", "")& "','" & replace(session ("strdrivinglicence"), "'", "")& "','" & replace(session ("strdob"), "'", "")& "','" & replace(session ("strage"), "'", "")& "','" & replace(session ("stremail"), "'", "")& "')"
 objConn.execute(SQLINSERT)


Thanks for the help.
0
rabbits2
Asked:
rabbits2
  • 6
  • 3
  • 3
  • +2
3 Solutions
 
nurbekCommented:
If session ("strage")="" then
response.write("please select age")
End if
0
 
rabbits2Author Commented:
No that bit works, sorry it is the INSERT statement that doesn't work this bit:
'" & replace(session ("strage"), "'", "")& "'

The error I am getting is 'mis match data type'.

Thanks
0
 
nurbekCommented:
If session ("strage")="" then
response.write("please select age")
Else
myChk = 1 ' if access database  myChk = true
End if

how do you define the database checkbox field ?

string? yes/no filed?

you should define myChk according to your field

or

you can enter the checkbox value on your form field value="true" or value="1"
then you can directly inster your session("strage")
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
rabbits2Author Commented:
In my Db I define the checkbox field yes/no
so how do I define myChk in my form which at the moment looks like this:

<td colspan="3" valign="top" class="text_2" style="height:21 "><input type="checkbox" name="txtage" value="checkbox"> <%displayMessage(17)%> </td>
0
 
nurbekCommented:
<%
session ("strage")=Request.Form ("txtage")
If session ("strage")<>"true" then
response.write("please select age")
Else
session ("strage")="false"
End if

'you can execuute your command
SQLINSERT = "INSERT INTO tbl_application(firstname,surname,username,password,mobile,driving_licence,dob,confirm_age,email) values('" & replace(session ("strfirstname"), "'", "")& "','" & replace(session ("strsurrname "), "'", "")& "','" & replace(session ("strusername"), "'", "")& "','" & replace(session ("strpassword"), "'", "")& "','" & replace(session ("strmob"), "'", "")& "','" & replace(session ("strdrivinglicence"), "'", "")& "','" & replace(session ("strdob"), "'", "")& "'," & session ("strage") & ",'" & replace(session ("stremail"), "'", "")& "')"
 objConn.execute(SQLINSERT)


%>

<td colspan="3" valign="top" class="text_2" style="height:21 "><input type="checkbox" name="txtage" value="true"> <%displayMessage(17)%> </td>
0
 
rabbits2Author Commented:
Still mis match data type error.  Could you explain why you have taken off the replace () around session("strage")

made all the changes you suggested.
0
 
rabbits2Author Commented:
And the reason it is only surrounded by "" rather than '""'

Just checking my code for this section:

if session ("strage")<>"true" then
response.redirect "caukus.asp?type=18&msg="&server.urlencode("Please confirm you are 18 or over")
exit function
elseif session ("strage")="false" then
exit function
elseif session ("stremployment")="" then
 response.redirect "caukus.asp?type=19&msg="&server.urlencode("Please enter your current employment")
exit function
end if
end fucntion
0
 
gyraCommented:
do

response.write(session("strage"))
response.end


then tell us what the results are. if it's nothing then that's your problem. it's not passing the value.

i suggest doing something like this, on the page put


strAge = false
if session("strAge")="true" then
strAge = true
end if

'then your insert

SQLINSERT = "INSERT INTO tbl_application(firstname,surname,username,password,mobile,driving_licence,dob,confirm_age,email) values('" & replace(session ("strfirstname"), "'", "")& "','" & replace(session ("strsurrname "), "'", "")& "','" & replace(session ("strusername"), "'", "")& "','" & replace(session ("strpassword"), "'", "")& "','" & replace(session ("strmob"), "'", "")& "','" & replace(session ("strdrivinglicence"), "'", "")& "','" & replace(session ("strdob"), "'", "")& "'," & strAge & ",'" & replace(session ("stremail"), "'", "")& "')"

 objConn.execute(SQLINSERT)


you should be using yes/no field in your database. if this doesn't work, it might be one of your other fields that's causing the issue.
0
 
Anthony PerkinsCommented:
You need to troubleshoot as follows:
SQLINSERT = "INSERT INTO tbl_application(firstname,surname,username,password,mobile,driving_licence,dob,confirm_age,email) values('" & replace(session ("strfirstname"), "'", "")& "','" & replace(session ("strsurrname "), "'", "")& "','" & replace(session ("strusername"), "'", "")& "','" & replace(session ("strpassword"), "'", "")& "','" & replace(session ("strmob"), "'", "")& "','" & replace(session ("strdrivinglicence"), "'", "")& "','" & replace(session ("strdob"), "'", "")& "','" & replace(session ("strage"), "'", "")& "','" & replace(session ("stremail"), "'", "")& "')"

Response.Write SQLINSERT   ' Add these lines temporarily
Response.End                              ' Add these lines temporarily

objConn.execute(SQLINSERT)

And the error should be patently obvious to you.
0
 
Anthony PerkinsCommented:
In the unlikely case that it is not, post the results of the following line:
Response.Write SQLINSERT
0
 
rabbits2Author Commented:
i am getting the error below:
Syntax error in INSERT INTO statement.

When I
Response.Write SQLINSERT  
Response.End
I get this:
INSERT INTO tbl_application(firstname,surname,username,password,mobile,confirm_age,email) values('Firstname','Surname','user89888','pass98998','078998878876',,'','email@hot.com')

My insert statement is as follows:
  SQLINSERT = "INSERT INTO tbl_application(firstname,surname,username,password,mobile,confirm_age,email) values('" & replace(session ("strfirstname"), "'", "")& "','" & replace(session ("strsurname"), "'", "")& "','" & replace(session ("strusername"), "'", "")& "','" & replace(session ("strpassword"), "'", "")& "','" & replace(session ("strmob"), "'", "")& "'," & strAge & ",'"& "','" & replace(session ("stremail"), "'", "")& "')"


Thanks fo ryour help.
0
 
John_LennonCommented:
you have an error in your sql statement

 SQLINSERT = "INSERT INTO tbl_application(firstname,surname,username,password,mobile,confirm_age,email) values('" & replace(session ("strfirstname"), "'", "")& "','" & replace(session ("strsurname"), "'", "")& "','" & replace(session ("strusername"), "'", "")& "','" & replace(session ("strpassword"), "'", "")& "','" & replace(session ("strmob"), "'", "")& "'," & strAge & ",'"& "','" & replace(session ("stremail"), "'", "")& "')"
-----------------^ this part!

when you get this
INSERT INTO tbl_application(firstname,surname,username,password,mobile,confirm_age,email) values('Firstname','Surname','user89888','pass98998','078998878876',,'','email@hot.com')

you are trying to insert 8 values in 7 fields

change your SQL statement to this
SQLINSERT = "INSERT INTO tbl_application(firstname,surname,username,password,mobile,confirm_age,email) values('" & replace(session ("strfirstname"), "'", "")& "','" & replace(session ("strsurname"), "'", "")& "','" & replace(session ("strusername"), "'", "")& "','" & replace(session ("strpassword"), "'", "")& "','" & replace(session ("strmob"), "'", "")& "'," & strAge & ",'" & replace(session ("stremail"), "'", "")& "')"
0
 
John_LennonCommented:
sorry, the bad part in SQL statement it's this
" & strAge & ",'"& "','" & replace(session ("stremail"), "'", "")& "')"
-------------------^

after strAge and before strEmail, you have '"& "',
0
 
rabbits2Author Commented:
Changed it to:

  SQLINSERT = "INSERT INTO tbl_application(firstname,surname,username,password,mobile,confirm_age,email) values('" & replace(session ("strfirstname"), "'", "")& "','" & replace(session ("strsurname"), "'", "")& "','" & replace(session ("strusername"), "'", "")& "','" & replace(session ("strpassword"), "'", "")& "','" & replace(session ("strmob"), "'", "")& "'," & strAge & ",'" & replace(session ("stremail"), "'", "")& "')"

and still getting syntax error, any ideas?
0
 
John_LennonCommented:
seems like you have a problem with
strAge
cause in the output you post before, there was no value for this variable

isn't it supposed to be session("strAge")??

also, you can try inserting this to the SQL statement
" & 0 & strAge & "
so strAge always will have a value

SQLINSERT = "INSERT INTO tbl_application(firstname,surname,username,password,mobile,confirm_age,email) values('" & replace(session ("strfirstname"), "'", "")& "','" & replace(session ("strsurname"), "'", "")& "','" & replace(session ("strusername"), "'", "")& "','" & replace(session ("strpassword"), "'", "")& "','" & replace(session ("strmob"), "'", "")& "'," & 0 & strAge & ",'" & replace(session ("stremail"), "'", "")& "')"
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 6
  • 3
  • 3
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now