Q. How do I use addslashes() and stripslashes() when dealing with HTML
forms and database INSERTs, UPDATEs and SELECTs?
A. It depends on the setting of the php.ini directive
"magic_quotes_g pc". By default, magic_quotes_gp c is On.
If magic_quotes_gp c is On:
Use stripslashes() for data which originates from an HTML form and is
shown in an HTML page after a roundtrip to the server.
Do not use addslashes().
If magic_quotes_gp c is Off:
Use addslashes() when INSERTing or UPDATEing data into the database.
Do not use stripslashes().
You can check the magic_quotes_gp c setting with the
get_magic_quote s_gpc() function.
Contrary to popular belief, it should never be necessary to use
stripslashes() on data which originates from a database SELECT. The
slashes which are added manually with addslashes(), or automagically
when magic_quotes_gp c is On, are only used to properly escape the data
before an INSERT or UPDATE and are themselves not stored in the database.
Refer:
+++++
@todo grammar checking by native English speaker. Maybe the 'Q' should
be something like "Why do I have backslashes in my form data"? Not sure.
JP
--
Sorry, <devnull@cauce. org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
forms and database INSERTs, UPDATEs and SELECTs?
A. It depends on the setting of the php.ini directive
"magic_quotes_g pc". By default, magic_quotes_gp c is On.
If magic_quotes_gp c is On:
Use stripslashes() for data which originates from an HTML form and is
shown in an HTML page after a roundtrip to the server.
Do not use addslashes().
If magic_quotes_gp c is Off:
Use addslashes() when INSERTing or UPDATEing data into the database.
Do not use stripslashes().
You can check the magic_quotes_gp c setting with the
get_magic_quote s_gpc() function.
Contrary to popular belief, it should never be necessary to use
stripslashes() on data which originates from a database SELECT. The
slashes which are added manually with addslashes(), or automagically
when magic_quotes_gp c is On, are only used to properly escape the data
before an INSERT or UPDATE and are themselves not stored in the database.
Refer:
+++++
@todo grammar checking by native English speaker. Maybe the 'Q' should
be something like "Why do I have backslashes in my form data"? Not sure.
JP
--
Sorry, <devnull@cauce. org> is a spam trap.
Real e-mail address unavailable. 5000+ spams per month.
Comment