brendan6 Posted November 13, 2007 Share Posted November 13, 2007 Does: $id = mysql_real_escape_string($_GET["id"]); $result = mysql_query("SELECT * FROM table WHERE id = '$id'"); Have the same affect as: $id = $_GET["id"]; $query = sprintf("SELECT * FROM table WHERE id = '%s'",mysql_real_escape_string($id)); $result = mysql_query($query); ? Link to comment https://forums.phpfreaks.com/topic/77219-mysql_real_escape_string/ Share on other sites More sharing options...
effigy Posted November 13, 2007 Share Posted November 13, 2007 Yes. Link to comment https://forums.phpfreaks.com/topic/77219-mysql_real_escape_string/#findComment-390942 Share on other sites More sharing options...
Dragen Posted November 13, 2007 Share Posted November 13, 2007 yeah pretty much. the sprintf simply replaces the %s with the $id. the mysql_real_escape_string on the first one is a must in pretty much every case for mysql insertion. It makes the string safe. Link to comment https://forums.phpfreaks.com/topic/77219-mysql_real_escape_string/#findComment-390943 Share on other sites More sharing options...
brendan6 Posted November 13, 2007 Author Share Posted November 13, 2007 Perfect..tahnk you Link to comment https://forums.phpfreaks.com/topic/77219-mysql_real_escape_string/#findComment-390958 Share on other sites More sharing options...
cooldude832 Posted November 13, 2007 Share Posted November 13, 2007 that isn't very safe, you should always test if the data type off a users input is valid, like run a is_numeric on it for example, and mysql_real_escape_strign Link to comment https://forums.phpfreaks.com/topic/77219-mysql_real_escape_string/#findComment-390963 Share on other sites More sharing options...
toplay Posted November 13, 2007 Share Posted November 13, 2007 that isn't very safe, you should always test if the data type off a users input is valid, like run a is_numeric on it for example, and mysql_real_escape_strign It looks like the "id" column in this case is probably an auto increment numeric data type, and hence would need to be validated to see if it's a valid integer. This is best done with ctype_digit() and not is_numeric() since that function allows periods and negative signs (dash) like in -1.2. <?php $nbr = 12.34; if (is_numeric($nbr)) echo 'The value of $nbr is numeric'; // Displays this! else echo 'The value of $nbr is not numeric'; if (ctype_digit($nbr)) echo 'The value of $nbr is an integer'; else echo 'The value of $nbr is not an integer'; // Displays this! ?> Link to comment https://forums.phpfreaks.com/topic/77219-mysql_real_escape_string/#findComment-390968 Share on other sites More sharing options...
cooldude832 Posted November 13, 2007 Share Posted November 13, 2007 anything is better than nothing though Link to comment https://forums.phpfreaks.com/topic/77219-mysql_real_escape_string/#findComment-390970 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.