How to insert ampersand into mysql using php?

How to insert ampersand into mysql using php? thanks in advance

When I execute the following code, “one” is saved in the database, but the “second” and the ampersand sign will not. Plz help me ...

$companyName ="one & second"; INSERT INTO registeration(companyName) VALUES('". $companyName ."')"; 
+4
source share
5 answers

I know this is old, but I just ran into this problem myself, and the problem turned out to be a screening problem with the ajax message, not a problem with mysql and php. I added encodeURIComponent (variabletopost) to the variable before sending it using ajax and it worked fine.

+4
source

Just like any other data, no special action is required.

+2
source

insert into table (field) values ('&')

+1
source

I know this is an old post, but try adding addslashes() to your php var:

 $companyName = addslashes("one & second"); 

Then, when php parses '&' (ampersand), it reads '\ &' (backslash-ampersand) instead of trying to create a link in the middle of the request.

0
source

I also ran into this type of problem and solved it using the javascript function encodeURIComponent (uri);

Instead of uri you should put your variable. then it will allow the use of all special characters.

-1
source

Source: https://habr.com/ru/post/1341767/


All Articles