Jump to content

[SOLVED] dashes appear beside quotation marks


contra10

Recommended Posts

That is sort of correct folks, however it isn't really for 'security purposes'.  It is called character escaping, and it is done so that MySQL knows where your query actually begins and ends.

 

Example:

<?php mysql_query("SELECT * FROM tbl WHERE name='bob's tackle'"); ?>

 

Without character escaping MySQL would think the query is SELECT * FROM tbl WHERE name='bob ... because what we view as an apostrophe to denote a plural tense, MySql sees as the closing apostrophe to the name condition.

 

So the above example should be:

<?php mysql_query("SELECT * FROM tbl WHERE name='bob\'s tackle'"); ?>

 

Prior to inserting data into MySQL tables you should use something like mysql_real_escape_string() (for non integer data). You generally won't need to 'strip slashes' if you use mysql_real_escape_string.

 

Character escaping goes well beyond PHP and MySQL ... it's done in nearly every syntax.

 

If you ever feel so inclined, you can trace the lineage of character escaping back to regular expressions.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.