HighDots Forums  

Apostrophe issue...

alt.discuss.html alt.discuss.html


Discuss Apostrophe issue... in the alt.discuss.html forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Shawn Wilson
 
Posts: n/a

Default Apostrophe issue... - 09-16-2005 , 04:09 PM






I have a photo album page where I pull captions and such from an SQL
database and inject into the resulting HTML.

My problem is with the use of an apostrophe (single quote) and other such
characters as they break my HTML. I'm also using javascript and it's a
problem there as well.

The method I use to insert such characters works without problems. In the
SQL I get what was intended... e.g. Ginny's Wedding

However when I pull it out I get this: (seemingly correct)

<a href="album.php?albumid=293&amp;frompage=1"><img id="img_two"
src="data/293/0/cover3.jpg" alt="Ginny's Wedding"
onMouseOver="switchit('Ginny's Wedding - Jun 11 2005');"
onMouseOut="clearit();"></a><br>

....But then my JS broken because the text is in single quotes and another
extra one breaks it.

How should I store such characters in SQL, or maybe just how should I read
them out so they can't break my code, yet they show up on the screen fine?

--
Shawn Wilson




Reply With Quote
  #2  
Old   
gmax
 
Posts: n/a

Default Re: Apostrophe issue... - 09-16-2005 , 04:18 PM






Shawn Wilson wrote:
Quote:
I have a photo album page where I pull captions and such from an SQL
database and inject into the resulting HTML.

My problem is with the use of an apostrophe (single quote) and other such
characters as they break my HTML. I'm also using javascript and it's a
problem there as well.

The method I use to insert such characters works without problems. In the
SQL I get what was intended... e.g. Ginny's Wedding

However when I pull it out I get this: (seemingly correct)

a href="album.php?albumid=293&amp;frompage=1"><img id="img_two"
src="data/293/0/cover3.jpg" alt="Ginny's Wedding"
onMouseOver="switchit('Ginny's Wedding - Jun 11 2005');"
onMouseOut="clearit();"></a><br

...But then my JS broken because the text is in single quotes and another
extra one breaks it.

How should I store such characters in SQL, or maybe just how should I read
them out so they can't break my code, yet they show up on the screen fine?

--
Shawn Wilson
You're twice off topic.
First, because this is a MySQL NG. We don't deal with HTML, PHP, or JS here.
Second, because this is an Italian language NG.

gmax

--
____ ____ _____ _ _
/ _ | \(____ ( \ / )
( (_| | | | / ___ |) X (
\___ |_|_|_\_____(_/ \_)
(_____|
MySQL Certified Professional
Sapere, saper fare, fare, far sapere
http://gmax.oltrelinux.com


Reply With Quote
  #3  
Old   
Els
 
Posts: n/a

Default Re: Apostrophe issue... - 09-16-2005 , 04:22 PM



gmax wrote:

Quote:
Shawn Wilson wrote:
I have a photo album page where I pull captions and such from an SQL
database and inject into the resulting HTML.

My problem is with the use of an apostrophe (single quote) and other such
characters as they break my HTML. I'm also using javascript and it's a
problem there as well.

The method I use to insert such characters works without problems. In the
SQL I get what was intended... e.g. Ginny's Wedding

However when I pull it out I get this: (seemingly correct)

a href="album.php?albumid=293&amp;frompage=1"><img id="img_two"
src="data/293/0/cover3.jpg" alt="Ginny's Wedding"
onMouseOver="switchit('Ginny's Wedding - Jun 11 2005');"
onMouseOut="clearit();"></a><br

...But then my JS broken because the text is in single quotes and another
extra one breaks it.

How should I store such characters in SQL, or maybe just how should I read
them out so they can't break my code, yet they show up on the screen fine?

You're twice off topic.
First, because this is a MySQL NG. We don't deal with HTML, PHP, or JS here.
Second, because this is an Italian language NG.
May I remmind you to look in the header to see to which newsgroups
this message was posted?
The OP has a question about a combination of HTML and MySQL, so he
crossposted it to two groups.

--
Els http://locusmeus.com/
Sonhos vem. Sonhos vão. O resto é imperfeito.
- Renato Russo -
Now playing: Madness - The Return of The Los Palmas 7


Reply With Quote
  #4  
Old   
Shawn Wilson
 
Posts: n/a

Default Re: Apostrophe issue... - 09-16-2005 , 05:02 PM



"gmax" <gmax_chiocciola_ (AT) _cpan_punto (DOT) _org> wrote

Quote:
Shawn Wilson

You're twice off topic.
First, because this is a MySQL NG. We don't deal with HTML, PHP, or JS
here.
Second, because this is an Italian language NG.

gmax
The title of the newsgroup is [alt.discuss.html] how is HTML not discussed
???

Also, if it's Italian language NG, then shouldn't there be like a it.alt or
something???

If it was my mistake, but how does a newsgroup named [alt.discuss.HTML] not
discuss HTML?

....and finally, while my question involves SQL... the problem lies with the
final HTML. Whether or not I pull from SQL, the problem really is that a
single quote needs to be shown in the HTML and I'm not sure how to do that
when it's already inside a set of single quotes.

--
Shawn Wilson




Reply With Quote
  #5  
Old   
Shawn Wilson
 
Posts: n/a

Default Re: Apostrophe issue... - 09-16-2005 , 05:04 PM



I really shouldn't cross post in the first place I guess... posts intended
for one group are going to two.

My mistake there, sorry.

--
Shawn Wilson



Reply With Quote
  #6  
Old   
Steve Sundberg
 
Posts: n/a

Default Re: Apostrophe issue... - 09-19-2005 , 05:53 AM



On Fri, 16 Sep 2005 21:09:04 GMT, "Shawn Wilson"
<shawnw_nospam_ (AT) _nospam_dvigroup (DOT) net> wrote:

Quote:
I have a photo album page where I pull captions and such from an SQL
database and inject into the resulting HTML.

My problem is with the use of an apostrophe (single quote) and other such
characters as they break my HTML. I'm also using javascript and it's a
problem there as well.

The method I use to insert such characters works without problems. In the
SQL I get what was intended... e.g. Ginny's Wedding [snip]
[newsgroups trimmed]

There are two possible solutions.

1. Escape the apostrophe with a backslash, e.g. Ginny\'s Wedding.
IIRC, this is universally recognized by Javascript, PHP, etc.

2. Use the extended ASCII symbol HTML code for the apostrophe, e.g.
Ginny's Wedding.

For future reference, you can consult this chart:
http://www.bbsinc.com/symbol.html

For more info on using escape codes in javascript:
http://www.devx.com/tips/Tip/13618

This is all pretty basic Javascript stuff. A quick search on Google
reveals thousands of sites with references to escape codes, etc.



Reply With Quote
  #7  
Old   
Shawn Wilson
 
Posts: n/a

Default Re: Apostrophe issue... - 09-19-2005 , 08:24 AM



"Steve Sundberg" <deejayREMOVETHE (AT) CAPITALLETTERSmm (DOT) com> wrote

Quote:
On Fri, 16 Sep 2005 21:09:04 GMT, "Shawn Wilson"
shawnw_nospam_ (AT) _nospam_dvigroup (DOT) net> wrote:

I have a photo album page where I pull captions and such from an SQL
database and inject into the resulting HTML.

My problem is with the use of an apostrophe (single quote) and other such
characters as they break my HTML. I'm also using javascript and it's a
problem there as well.

The method I use to insert such characters works without problems. In the
SQL I get what was intended... e.g. Ginny's Wedding [snip]

[newsgroups trimmed]

There are two possible solutions.

1. Escape the apostrophe with a backslash, e.g. Ginny\'s Wedding.
IIRC, this is universally recognized by Javascript, PHP, etc.

2. Use the extended ASCII symbol HTML code for the apostrophe, e.g.
Ginny's Wedding.

For future reference, you can consult this chart:
http://www.bbsinc.com/symbol.html

For more info on using escape codes in javascript:
http://www.devx.com/tips/Tip/13618

This is all pretty basic Javascript stuff. A quick search on Google
reveals thousands of sites with references to escape codes, etc.
Yeah, that's what I ended up doing is slashing it with addslashes()...
although that created it's own little bump since I use that same php
variable for the image's alt tag and HTML leaves the slash there so I got
"Ginny\'s Wedding" as the image alt tooltip. Had to add another variable
(one slashed and one not) to get it right.

The thing with that extended ASCII encoding is that it still broke my JS. I
don't know which character it didn't like, the ampersand or the semicolon
maybe, but either way it also broke the script. The escaping is what I had
to go with.

Would anyone suggest escaping things before I put them into SQL in the first
place? Currently the method I use to insert into SQL has no problem with
not escaping them... probably because it's escaping them by itself only the
resulting SQL does not have slashes in it.

Is it just a general good practice to write [Ginny\'s Wedding] to the DB
instead of [Ginny's Wedding] ? Or does it not matter as long as I make it
work for me either way?

--
Shawn Wilson




Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.