Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping using slashes and then using stripslashes PHP

Tags:

php

In my code i am using addslashes to escape certain characters while inserting them into the database and when i send some information out i use stripslashes to remove those slashes, the situation is stripslashes function removes all the slashes so if i need to send any string which has backslashes those also get removed. How can i retain those required slashes.

Any help will be greatly appreciate.

like image 468
pks83 Avatar asked Dec 19 '25 00:12

pks83


2 Answers

You might want to try using mysql_real_escape_string. You don't have to unescape it, and it is safe for database use.

Better yet, use prepared statements

like image 169
Tyler Carter Avatar answered Dec 21 '25 14:12

Tyler Carter


You can try using PDO prepared statements when inserting to database so you don't need to worry about escaping anything.

like image 37
ian Avatar answered Dec 21 '25 14:12

ian