Link to home
Start Free TrialLog in
Avatar of rabbits2
rabbits2

asked on

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.
Avatar of nurbek
nurbek

If session ("strage")="" then
response.write("please select age")
End if
Avatar of rabbits2

ASKER

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
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")
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>
SOLUTION
Avatar of nurbek
nurbek

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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
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.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In the unlikely case that it is not, post the results of the following line:
Response.Write SQLINSERT
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.
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"), "'", "")& "')"
sorry, the bad part in SQL statement it's this
" & strAge & ",'"& "','" & replace(session ("stremail"), "'", "")& "')"
-------------------^

after strAge and before strEmail, you have '"& "',
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?
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial