how to insert ampersand in mysql using php?
How to i开发者_如何学Gonsert ampersand in mysql using php? Thanks in advance
When I execute the following code the “one” is saves in database but the “ second” and ampersand sign won’t. plz help me…
$companyName ="one & second";
INSERT INTO registeration(companyName) VALUES('". $companyName ."')";
I know this is old but I just ran into this issue myself and the issue turned out to be an escaping issue with ajax post rather than an issue with mysql and php. I added encodeURIComponent(variabletopost) to the variable before posting it with ajax and it worked great.
Exactly the same way as any other data, no special action required.
insert into table (field) values ('&')
I know it's an old post but,
try adding addslashes()
to your php var:
$companyName = addslashes("one & second");
Then, when php parses the '&' (ampersand) , it reads '\&' (backslash-ampersand) instead of trying to create a reference in the middle of the query.
I also faced this type of issue and solved by using javascript function encodeURIComponent(uri);
In place of uri you have to put your variable. then it will allow all special character.
精彩评论