Generic filters
Exact matches only

Save an Ampersand (&) to MySql Database

20th March 2019

Jquery - Forms-Posting

jquery icon

Problem: – I could not save the ampersand (&) symbol to my database
Symptom: – The text was cut off at the point the ampersand should appear.

When inputting “Dog & Cat” it would appear in the database as just “Dog”

I had a text area which a user was typing in text, and whenever the form was submitted to save, the Jquery would get the text area contents with no problem as I could alert it out as normal.

I then sent this via Ajax to the PHP page, and collected the post data and tried to save it to the database, but it was constantly cut off. So I tried the following things. (Thinking that it was the inputting of the data where the problem was).

I gave up this method, and thought about the sending via ajax.

I eventually found the answer and had to encode the URL using the code below. the window.escape did the trick. It was getting confused as (&) in a url can confuse it. It was not a Mysql escape that was needed but a JavaScript escape!

Was this code snippet helpful?

Comment on this Code Snippet?