Message Board

~mR.bLaCk~

New Member
I just finished designing a message board located at http://www.thezambian.com/message.aspx however whenever I post a message with an apostrophe (') or some strange character the board generates an error. <BR><BR>Does anyone know why this might be so?at what point is the error ?<BR>This seems like an SQL problem to me as when you wan't the apostrophie in the SQL ,you need to double it<BR><BR>ex Insert into test (name) values ('Marc's Place') This will fail<BR>ex Insert into test (name) values ('Marc''s Place') This will insert marc's place in the name .<BR><BR>if this is not it ... Please be more specific then i got an error,<BR>give some juice to work on... <BR>no heart feelingWhenever you use an apostrophe it'll blow up the code. Here's what you do to fix it:<BR><BR>If you have numerous fields (name, email, message) that you enter into your database using the input string: <BR><BR>"Insert INTO Table ( FirstName ) Values ( '" & txtFirstName.Text & "' )" myConnection )<BR><BR>Or something like that (where you get the first name value from the form), then above the sql statement insert this code:<BR><BR> Dim strFirstName as string<BR> strFirstName = txtFirstName.Text & ""<BR> strFirstName = Replace(strFirstName,"'","''")<BR><BR>And change your sql statement to read like this:<BR><BR>"Insert INTO Table ( FirstName ) Values ( '" & strFirstName & "' )" myConnection )<BR><BR>That gets rid of the apostrophes so they woun't blow anything up. You can do it with any of the symbols, and if there are multiple fields just change FirstName to whatever your input names are.http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=137
 
Back
Top