Using the " and ' characters in html text box

tester89 at my-deja.com tester89 at my-deja.com
Fri May 12 13:51:23 EDT 2000


I have a problem with using the " and ' characters via a web page
using a scrolling text box. In order to place the data into
a mysql database I must change the " and ' characters to something
else or esacpe them so I can put them in the database.

Data Such as:

string data: jdhasjdhdfjfhdjf\n"Hello there"\n'Bye1'\n

tmpdata="insert into table values('%s')" % (string data)

cursor.execute(tmpdata)

This of course will bring up an error since the ' character is used
in both the data and the tmpdata string causing corrupt input. Then I
came up with the idea of using base64 encoding on the string data.
Works like a charm!

The problem then lies getting the data back out. Decoding the base64 is
no problem but when forming the html code it malforms the html and
will not display correctly. So if I were to do:

print "<input type='text' name='foo' value='%s'>" % (string data)

The string which contains the ' and " characters will corrupt the above
line causing it not to display in the browser.

So what i'm asking is how can I get this data into the database and
back out again to display properly. Any new cool functions out there i'm
not aware of at this time? Any little cool convert functions someone has
made for this type problem? I must not be the only one interested in
getting ALL inputed data from a user into a databse no matter what data
is in the field. Examples are greatly appreciated.

Thanks.


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list