MySQL Forums
Forum List  »  PHP

Adding and removing slashes
Posted by: Matt Camill
Date: April 18, 2013 01:27PM

Hi I’m in a class being taught PHP and MySql, and I’m posting this question more or less for clarification as to when and how you would use functions that add and remove slashes when inserting/retrieving data from the database. I can’t seem to find solid guidance with my current resources, so let me tell you what I’ve gathered so far, and please either correct me or expand on it so I can get the whole picture.

The best function to use for adding slashes to a record being inserted into a MySql database is mysqli_real_escape_string(). This much is simple and clear, but my big question here, is do you use this function only for data you intend to store as a string, or for all types including numeric?

Second question, we’re being taught to use floatval() on floating point numbers before we insert them into the database. Should we use the corresponding function for integer types as well? Anything else I need to know in regards to storing numeric types in a MySql database?

And lastly, my third major question, is the generic stripslashes() function good to remove slashes from data that you query, or is there a MySql specific one I should use instead? It shouldn’t make a difference I would think in this case, since it just removes the slashes for the purpose of your query. It doesn’t change the actual record in the database, right?

Any help on clearing all this up, so I can go about doing things the right way before I form any bad habits, would be immensely appreciated :)

Options: ReplyQuote


Subject
Written By
Posted
Adding and removing slashes
April 18, 2013 01:27PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.