Page 1 of 1

add/stripslashes question

Posted: Wed Mar 05, 2003 5:39 pm
by Sevengraff
OK, im using php and MySQL. I get input from a form and use addslashes() before i put the text into a SQL table. when i print out the text, i use stripslashes(), and this works for the most part.
but i noticed that if i post something like this:
\\\\\\\\\\\\\\\
///////////////
it becomes
\\\\\\\
///////////////
how should i use the slashes function to make text show up propperly?

Posted: Wed Mar 05, 2003 6:36 pm
by hob_goblin

Posted: Wed Mar 05, 2003 6:53 pm
by Sevengraff
i see, so i should use mysql_escape_string to put the text in, and stripslashes when i want to print it out.

Posted: Wed Mar 05, 2003 9:10 pm
by hob_goblin
yes, or addslashes(), but i like mysql_escape_string()

Does it work?

Posted: Wed Mar 05, 2003 10:05 pm
by Sevengraff
but, thats what i've been doing before! i used addslashes() when i put stuff in, and stripslashes when i print stuff on the way out, but things still come out wrong. should i use them in a different order?

Posted: Wed Mar 05, 2003 10:11 pm
by hob_goblin
Sevengraff wrote:but, thats what i've been doing before! i used addslashes() when i put stuff in, and stripslashes when i print stuff on the way out, but things still come out wrong. should i use them in a different order?
Try doing addslashes twice.

Posted: Wed Mar 05, 2003 10:16 pm
by Sevengraff
that works, but it seems stupid to do it twice.
i'll just use addslashes once, and not use stripslashes, and see how that goes

--- edit ---

yes, this works better.

Posted: Wed Mar 05, 2003 10:41 pm
by hob_goblin
When the string is passed into the DB, the slashes are removed upon entry.

Posted: Wed Mar 05, 2003 10:55 pm
by Sevengraff
oh, ok. things make sense then.
Thanks!!