Quantcast
Channel: MySQL Forums - PHP
Viewing all articles
Browse latest Browse all 938

Adding and removing slashes (1 reply)

$
0
0
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 :)

Viewing all articles
Browse latest Browse all 938

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>