Forums

ASP

This topic is locked

Please help !!! Single quotes in ASP/SQ

Posted 08 Mar 2006 14:09:11
1
has voted
08 Mar 2006 14:09:11 Ado Ado posted:
Hi guys I am trying to get my head around single quotes problem and insertion into my Access database. Now I can insert all of my fields with no problems into my DB as long as no single quotes are included " ' ".

For example the word " don't " would cause an syntax error. I am aware of why this is happending as my SQL statement is using single quotes just have no idea how to fix it.


Let me show you what my code looks like:
Any suggestion would be very helpful:


<pre id=code><font face=courier size=2 id=code>&lt;!--ASP CODE INSERTION AND FORM COMPLETION --&gt;
&lt;%
Dim connection, query, data, input, store, dbpath

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

Call connection.Open("davidpender_D1_Survey"

'Section 1 input code

query ="insert into S1_Demographics_Data (S1_Q1_Company, S1_Q1_Code, S1_Q1_NameUnknown, S1_Q2_Tel, S1_Q2_Email, S1_Q3_Gender, S1_Q4_Competence, S1_Q5_Department, S1_Q5_Title, S1_Q5_DepLocation, S1_Q6_Age, S1_Q7_PosnOrg, S1_Q8_TimeWorked, S1_Q9_TimeWorkedFin, S1_Q10_Education"

query = query & ""
query = query & " VALUES"
query = query & "("
query = query & " ' " & Request.Form("S1.Q1.Company" & "', "
query = query & " ' " & Request.Form("S1.Q1.Code*" & "', "
query = query & " ' " & Request.Form("unknown" & "', "
query = query & " ' " & Request.Form("Tel" & "', "
query = query & " ' " & Request.Form("Email" & "', "
query = query & " ' " & Request.Form("Gender*" & "', "
query = query & " ' " & Request.Form("Compatance*" & "', "
query = query & " ' " & Request.Form("Department*" & "', "
query = query & " ' " & Request.Form("Title*" & "', "
query = query & " ' " & Request.Form("DepLocation*" & "', "
query = query & " ' " & Request.Form("Age*" & "', "
query = query & " ' " & Request.Form("position*" & "', "
query = query & " ' " & Request.Form("YY" &" . "& Request.Form("MM" & "', "
query = query & " ' " & Request.Form("YY2" &" / "& Request.Form("MM2" & "', "
query = query & " ' " & Request.Form("education" & "'"
query = query & ""

connection.Execute query
if err&lt;&gt;0 then
Response.Write("No data has been inserted into the database."
else
Response.Write("Survey Recorded!"
end if
call connection.Close()
%&gt;

</font id=code></pre id=code>


<pre id=code><font face=courier size=2 id=code>THIS IS MY FORM

&lt;form id="form" name="form" method="post" action="insert2.asp"&gt;
&lt;input type="text" name="S1.Q1.Company" /&gt;
...... plus all the other fields

&lt;input type="submit" name="Submit" value="Submit" /&gt;
&lt;/form&gt;

PLEASE ANYONE, this is killing me!!</font id=code></pre id=code>

Replies

Replied 08 Mar 2006 14:24:41
08 Mar 2006 14:24:41 Steweb . replied:
HI !

why don't use Replace(Value, "'", "''" !

Replace(request.form("Title*", "'", "''"


Steweb

visit my website
www.steweb.net

Reply to this topic