Home > ASP Development > So simple, yet so complicated

So simple, yet so complicated



quick question.

what is the best method for taking html code, and inserting it into a database? For example, want to create a newsletter with a WYSIWYG editor, which I want stored in my SQL Server 2000 database. However, when it comes to fields such as <p class="whatever"> the quotes will cause errors.

Do I need to convert the form variable to something that will let me insert into my database, and same goes for getting the data back out to display it on a web page.

Sorry if this seems simple, or have heard it 1000 times before, but I cannot find a tutorial that deals with this situation.



Thanks,

Mick

    
Guest


Quote:
Originally Posted by mickyjtwin
quick question.

what is the best method for taking html code, and inserting it into a database? For example, want to create a newsletter with a WYSIWYG editor, which I want stored in my SQL Server 2000 database. However, when it comes to fields such as <p class="whatever"> the quotes will cause errors.

Do I need to convert the form variable to something that will let me insert into my database, and same goes for getting the data back out to display it on a web page.

Sorry if this seems simple, or have heard it 1000 times before, but I cannot find a tutorial that deals with this situation.



Thanks,

Mick




Its mostly just the single quotes that'll give you problems, you could create a function and wrap around your insert variable to replace any single quotes with something else like a tilda character ~ and as you said run the reverse when outputting it to the screen.



There are other examples freely available on the web that you could copy into your code -- just do a google search on the subject.



Try keyword like replace single quote in Insert statement.

Was this answer helpful ? Yes No   
Guest


i don't have a problem with replacing the single quotes, i just use the replace function and turn ' into ''. It's when the HTML code from the WYSIWYG editor get's more advanced, and starts using " for centering <p>'s etc.

I've tried searching for this stuff, but have come up empty handed. Every WYSWYG editor I've looked at doesn't give examples or tutorials on using with a database. Very frustating to say the least.



Mick

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by mickyjtwin
i don't have a problem with replacing the single quotes, i just use the replace function and turn ' into ''. It's when the HTML code from the WYSIWYG editor get's more advanced, and starts using " for centering <p>'s etc.

I've tried searching for this stuff, but have come up empty handed. Every WYSWYG editor I've looked at doesn't give examples or tutorials on using with a database. Very frustating to say the least.



Mick




What WYSIWYG editor you using -- DreamWeaver? Y'know you can get by without the double quotes on HTML elements. Just a thought, but have you tried to code it yourself in code view, you'll learn a lot faster than drag and drop scenarios.

Was this answer helpful ? Yes No   
Guest


This is my scenario...

My asp page loads up, and in it it has a textarea which has my wysiwyg editor applied, i.e. tinymce.

The form posts to my dump.asp, which requests the text variable.

Example:

File start.asp

<form action="dump.asp" method="post">

<textarea name="whatever" id="whatever"><textarea>

</form>

*************************8

File dump.asp

<%

SQL = "INSERT INTO myTable(stuff) VALUES('" & request.Form("whatever") & "')"

objConn.Execute(SQL)

%>

*************************

This works fine if the HTML coming from the textarea just contains <p>Stuff blah blah</p><strong>blah</strong> etc.

But with a more complex WYSIWYG editor, you can change things like <p align="center"> etc. With the double quotes, the problem lies in the SQL call. I don't know if I'm stupid and am missing something really simple, or what.

Nobody goes into detail about how data should be taken from a WYSIWYG editor, and placed into a database using ASP.



Thanks for you time pws1970, I appeciate your efforts

Mick

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by mickyjtwin

This works fine if the HTML coming from the textarea just contains <p>Stuff blah blah</p><strong>blah</strong> etc.

But with a more complex WYSIWYG editor, you can change things like <p align="center"> etc. With the double quotes, the problem lies in the SQL call. I don't know if I'm stupid and am missing something really simple, or what.

Nobody goes into detail about how data should be taken from a WYSIWYG editor, and placed into a database using ASP.




You should be able to replace the double quote " with 2 single quotes '', which will still work with HTML. Or at least that's the wya I do it, and never had a problem with it.



HTH,



Hadyn.

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by mickyjtwin
This is my scenario...

My asp page loads up, and in it it has a textarea which has my wysiwyg editor applied, i.e. tinymce.

The form posts to my dump.asp, which requests the text variable.

Example:

File start.asp

<form action="dump.asp" method="post">

<textarea name="whatever" id="whatever"><textarea>

</form>

*************************8

File dump.asp

<%

SQL = "INSERT INTO myTable(stuff) VALUES('" & request.Form("whatever") & "')"

objConn.Execute(SQL)

%>

*************************

This works fine if the HTML coming from the textarea just contains <p>Stuff blah blah</p><strong>blah</strong> etc.

But with a more complex WYSIWYG editor, you can change things like <p align="center"> etc. With the double quotes, the problem lies in the SQL call. I don't know if I'm stupid and am missing something really simple, or what.

Nobody goes into detail about how data should be taken from a WYSIWYG editor, and placed into a database using ASP.



Thanks for you time pws1970, I appeciate your efforts

Mick




function




Code:


Function StripDoubleQuotes(sTempString)
StripDoubleQuotes = replace(sTempString, """, "")
End Function






sql




Code:


   SQL = "INSERT INTO myTable(stuff) VALUES('" & StripDoubleQuotes(request.Form("whatever")) & "')"
objConn.Execute(SQL)






will retain the code <p align=center> instead of <p align="center">

Was this answer helpful ? Yes No   
Guest


The only problem I have with " is ASP related, rather than SQL related.



The simple solution is to use "" instead of ". This escapes the " to vbscript

and stops it terminating the string.

Was this answer helpful ? Yes No   
Guest


I convert all single and double quotes into their ascii equivalents before inserting them in to the database and then doing the reverse when pulling the data from the database.

Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by Padwah
I convert all single and double quotes into their ascii equivalents before inserting them in to the database and then doing the reverse when pulling the data from the database.




Nice one Padwah.



Will be back later Padwah to give some rep for you when I'm allowed.

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved