add/stripslashes question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

add/stripslashes question

Post 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?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post 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.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

yes, or addslashes(), but i like mysql_escape_string()

Does it work?
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post 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?
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post 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.
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post 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.
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

When the string is passed into the DB, the slashes are removed upon entry.
User avatar
Sevengraff
Forum Contributor
Posts: 232
Joined: Thu Apr 25, 2002 9:34 pm
Location: California USA
Contact:

Post by Sevengraff »

oh, ok. things make sense then.
Thanks!!
Post Reply