The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Apostrophe from database stopping javascript!?!

Hello - we had someone write this script for us a few years ago and we thought it was working fine until this week. It uses javascript to generate a dependant drop down menu eg. Depending on what the user chooses in the first drop down menu, (in this case a manual/book title) the second drop down displays the chapter/category headings that are available within that manual and then the users uploads a file that appears under that heading.

If our user adds a chapter/category heading with an apostrophe in it the script quits and the second drop down does not display the corresponding chapter headings.

We are storing the info in a mysql database and use php and javascript to extract the data/build the drop down menus.

We tried to use the addslashes and stripslashes php functions but can't get them to work, we also tried adding \' into the chapter title record in the database (eg. Chapter one - O\'Malleys Journey) to see if that would work but had no luck with that either.

Can anyone help? We can post the entire script if someone wants more info.
Thanks!

Thanks for the suggestion, we tried it and the drop down functioned properly but the text in the menu appeared as apersand pound 39 semicolon rather than an apostrophe which isn't really user friendly.

Because our client is entering the data we need to find a way to automatically replace the apostrophe or escape it automatically as we can't really ask them to type in apersand pound 39 semicolon every time they want to use an apostrophe

We have used the addslashes function in php and it solved this problem but with the added javascript in this code it seems to be more difficult.

It appears you have only one choice:
Use Javascript validation to modify the text before it is submitted to the database; replacing all apostrophes with some unique sequence of characters.
That means, also, your PHP will need to 'decode' the data as it comes out of the database.
Can you impose a rule on your users to NOT use that character? Javascript validation could enforce the rule.
There may be another solutions and I hope someone else will speak up on this thread.