chaiwei Posted November 7, 2008 Share Posted November 7, 2008 Hi all, I am a newbie in php. I not really understand about the mysql_real_escape_string() and addslashes(). As I know so far mysql_real_escape_string() is better.(somebody told me) But I don't know why? Can Some One explain to me PLS?? Thanks in advance. Have a Nice day! regards, chaiwei Quote Link to comment https://forums.phpfreaks.com/topic/131765-solved-different-between-the-mysql_real_escape_string-and-addslashes/ Share on other sites More sharing options...
Mchl Posted November 7, 2008 Share Posted November 7, 2008 Because mysql_real_escape_string() is specifically crafted for use with mysql database, and it also takes into consideration the current character set of the connection (that's why there must be a connection handle available, before you can use mysql_real_escape_string() Read more Quote Link to comment https://forums.phpfreaks.com/topic/131765-solved-different-between-the-mysql_real_escape_string-and-addslashes/#findComment-684438 Share on other sites More sharing options...
chaiwei Posted November 8, 2008 Author Share Posted November 8, 2008 Hi, Thanks for the responding. But if I didn't include the connection in the mysql_real_escape_string(), It is still work right? (connection include in top)-->$conn=mysql_connect($host,$usr,$pw); I just use $value=mysql_real_escape_string($value); I have tried,it works. But mysql_real_escape_string($value,$conn) require two input arguement right? value and the mysql connection. Another issue, I saw in php.net. If: $value=abc's; $value1=abc\'s; $value=mysql_real_escape_string($value,$conn); $value1=mysql_real_escape_string($value1,$conn); echo $value; (value= abc\'s) echo $value1; (value= abc\\'s) So the $value1 is wrong right? which i saw in forum they used get_magic_quotes_gpc() to validate; but my question is if it is not get, post, or cookie; then the function is not use at all right? Please advise.Thanks for any help given. regards, chaiwei Quote Link to comment https://forums.phpfreaks.com/topic/131765-solved-different-between-the-mysql_real_escape_string-and-addslashes/#findComment-685092 Share on other sites More sharing options...
Mchl Posted November 8, 2008 Share Posted November 8, 2008 mysql_real_escape_string() will work with only one parameter. The second one, is needed, if for example you work with two database connections at once. Then you have to specify, which connection the function should work with. And yes, this function is in general used to escape data entered by users. No need to escape data, that you yourself (as a programmer) escaped before. Quote Link to comment https://forums.phpfreaks.com/topic/131765-solved-different-between-the-mysql_real_escape_string-and-addslashes/#findComment-685204 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.