Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: SQL/ASP problem


Message #1 by "Duncan Soar" <dsoar@s...> on Fri, 18 May 2001 11:18:02
hello - I'm fairly new to this, so sorry if it's a stupid question... My 

problem is that I'm trying to submit some information from a form into a 

database. All the other entries in the form work fine, but when I get 

people to insert a personal description that involves either ' or " it 

seems to confuse the sql statement. Don't know if it's maybe because I've 

been messing about with Frontpage & Dreamweaver a bit too.



the rogue line goes like this - the offending value in particular being 

the "request.form ("Personaldescription")" bit... Any help greatly 

appreciated. Thanks





str = "insert into assistants (FirstName, LastName, Address1, Address2, 

Sex, City, Postcode, Country, Age, AgeRange, Mobile, Email, Website, 

Experience, ExperienceType, Photographersworkedwith, Personaldescription, 

Driver, Smoker, Username, MyPassword) values('" & request.form

("FirstName") &  "','" & request.form("LastName") & "','" & request.form

("Address1") & "','" & request.form("Address2") & "','" & request.form

("Sex") &  "','" & request.form("City") & "','" & request.form("Postcode") 

& "','" & request.form("Country") & "','" & request.form("Age") &  "','" & 

stragerange & "','" & request.form("Mobile") & "','" & request.form

("Email") &  "','" & request.form("Website") & "','" & request.form

("Experience") & "','" & request.form("ExperienceType") &  "','" & 

request.form("Photographersworkedwith") & "','" request.form

("Personaldescription") & "','" & request.form("Driver") &  "','" & 

request.form("Smoker") & "','" & request.form("UserName") & "','" & 

request.form("Password") & "')" 
Message #2 by "Craig Flannigan" <ckf@k...> on Fri, 18 May 2001 11:51:34 +0100
Does it only occurr when a user enters a personal description that contains

' ?



If a description has a ' mark in it, you need to double it so that ' becomes

'' (two singe quotes)



To do this, use the replace command.



e.g "This bit of text wasn't allowed into SQL"  would turn into "This bit of

text wasn''t allowed into SQL"



The code you need is.......

strDescription = Replace(Request.Form("PersonalDescription"),"'","''")





Hope this helps

Craig.





-----Original Message-----

From: Duncan Soar [mailto:dsoar@s...]

Sent: Friday 18 May 2001 11:18

To: ASP Databases

Subject: [asp_databases] SQL/ASP problem





hello - I'm fairly new to this, so sorry if it's a stupid question... My

problem is that I'm trying to submit some information from a form into a

database. All the other entries in the form work fine, but when I get

people to insert a personal description that involves either ' or " it

seems to confuse the sql statement. Don't know if it's maybe because I've

been messing about with Frontpage & Dreamweaver a bit too.



the rogue line goes like this - the offending value in particular being

the "request.form ("Personaldescription")" bit... Any help greatly

appreciated. Thanks





str = "insert into assistants (FirstName, LastName, Address1, Address2,

Sex, City, Postcode, Country, Age, AgeRange, Mobile, Email, Website,

Experience, ExperienceType, Photographersworkedwith, Personaldescription,

Driver, Smoker, Username, MyPassword) values('" & request.form

("FirstName") &  "','" & request.form("LastName") & "','" & request.form

("Address1") & "','" & request.form("Address2") & "','" & request.form

("Sex") &  "','" & request.form("City") & "','" & request.form("Postcode")

& "','" & request.form("Country") & "','" & request.form("Age") &  "','" &

stragerange & "','" & request.form("Mobile") & "','" & request.form

("Email") &  "','" & request.form("Website") & "','" & request.form

("Experience") & "','" & request.form("ExperienceType") &  "','" &

request.form("Photographersworkedwith") & "','" request.form

("Personaldescription") & "','" & request.form("Driver") &  "','" &

request.form("Smoker") & "','" & request.form("UserName") & "','" &

request.form("Password") & "')"

---

* Fast, Full-Featured Microsoft® Excel Web Reports & Charts!

A breakthrough in high performance Web application development, SoftArtisans

ExcelWriter 1.1 supports native Excel charting, image insertion, and

advanced functions & formatting. One click generates presentation-quality

Excel spreadsheets-and ExcelWriter performs over 100 times faster than the

Excel Object. Several editions, including ExcelWriterFREE, are available.

URL:<http://adtracking.wrox.com/track.asp?x=p2p%2Fe%2Fd%26w%2Fsoftart&url=ht

tp://www.softartisans.com/softartisans/excelwriter.html>




$subst('Email.Unsub')





_____________________________________________________________________

This message has been checked for all known viruses by Star Internet

delivered through the MessageLabs Virus Scanning Service. For further

information visit http://www.star.net.uk/stats.asp



Message #3 by "Duncan Soar" <dsoar@s...> on Sat, 19 May 2001 11:39:05
Thanks a million Craig - that was exactly it. You've got rid of a bad 

headache!



Duncan







> Does it only occurr when a user enters a personal description that 

contains

> ' ?

> 

> If a description has a ' mark in it, you need to double it so that ' 

becomes

> '' (two singe quotes)

> 

> To do this, use the replace command.

> 

> e.g "This bit of text wasn't allowed into SQL"  would turn into "This 

bit of

> text wasn''t allowed into SQL"

> 

> The code you need is.......

> strDescription = Replace(Request.Form("PersonalDescription"),"'","''")

> 

> 

> Hope this helps

> Craig.

> 

> 

> -----Original Message-----

> From: Duncan Soar [mailto:dsoar@s...]

> Sent: Friday 18 May 2001 11:18

> To: ASP Databases

> Subject: [asp_databases] SQL/ASP problem

> 

> 

> hello - I'm fairly new to this, so sorry if it's a stupid question... My

> problem is that I'm trying to submit some information from a form into a

> database. All the other entries in the form work fine, but when I get

> people to insert a personal description that involves either ' or " it

> seems to confuse the sql statement. Don't know if it's maybe because I've

> been messing about with Frontpage & Dreamweaver a bit too.

> 

> the rogue line goes like this - the offending value in particular being

> the "request.form ("Personaldescription")" bit... Any help greatly

> appreciated. Thanks

> 

> 

> str = "insert into assistants (FirstName, LastName, Address1, Address2,

> Sex, City, Postcode, Country, Age, AgeRange, Mobile, Email, Website,

> Experience, ExperienceType, Photographersworkedwith, Personaldescription,

> Driver, Smoker, Username, MyPassword) values('" & request.form

> ("FirstName") &  "','" & request.form("LastName") & "','" & request.form

> ("Address1") & "','" & request.form("Address2") & "','" & request.form

> ("Sex") &  "','" & request.form("City") & "','" & request.form

("Postcode")

> & "','" & request.form("Country") & "','" & request.form("Age") &  "','" 

&

> stragerange & "','" & request.form("Mobile") & "','" & request.form

> ("Email") &  "','" & request.form("Website") & "','" & request.form

> ("Experience") & "','" & request.form("ExperienceType") &  "','" &

> request.form("Photographersworkedwith") & "','" request.form

> ("Personaldescription") & "','" & request.form("Driver") &  "','" &

> request.form("Smoker") & "','" & request.form("UserName") & "','" &

> request.form("Password") & "')"

> ---


  Return to Index