PDA

Click to See Complete Forum and Search --> : is addslashes() really needed?


jimot
Mar 6th, 2006, 08:13 PM
hi all.. do you really need addslashes() to store data into mysql?
Because I tried this:

$item = "jim's";
$item = addslashes($item);

if I echo $item then $item is "jim\'s" then I store $item into mysql database table.

But when I retrieve it using SELECT, even if I don't use stripslashes(), the result is "jim's" NOT "jim\'s". So what do I use the addslashes() for in the first place? :confused:

thanks

juanmf
Mar 7th, 2006, 08:30 AM
try using double addslashes. in linux "\" is used to "escape some character" to not being interpreted as special ones. so the "\" die in the process. if you want:
"jim\'s" stored
i think it should lok like:
$item = "jim\\\'s" (\ to escape \ and \ to escape ')
try it and tell me. becouse i didnīt tested. just a heartbit.
edited one minute later
OK i tryed it. it works. :wave: