HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Submitting a text to the database
Post new topic   Reply to topic    HTML Help Forum Index -> ASP
View previous topic :: View next topic  
Author Message
jim b



Joined: 12 May 2006
Posts: 14

PostPosted: Sat Jul 22, 2006 10:47 am     Submitting a text to the database Reply with quote

at the moment I have the following code, for a local email system on my Intranet:
Code:
Set objComm = Server.CreateObject("ADODB.Command")

  objComm.ActiveConnection = strConnect
  objComm.CommandText="INSERT INTO mail ([sender], [recipient], [subject], [message], [locked]) VALUES ('" & user & "', '" & recipient & "', '" & subject & "', '" & message & "', '1')"
                     
  objComm.Execute intNoOfRecords
  Set objComm = Nothing


However if a user includes a ' into their message they get an error message as the sql statement thinks it is moving on to fill the next feild.

How can I make the message variable submit regardless of any character that I put in to it (including ' )

Thankyou
degsy



Joined: 23 Feb 2005
Posts: 2440
Location: North East, UK

PostPosted: Mon Jul 24, 2006 10:30 am     Reply with quote

You need to use validation to prevent SQL injections.

A simple validation is to use Replace

Code:


str = "str with a ' quote"

newStr = Replace(str,"'","''")
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> ASP All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
 
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial