notepad Posted May 7, 2007 Share Posted May 7, 2007 Hi, In the page about mysql_real_escape_string on www.php.net there is a 'Best practice method', code using sprintf. I understand sprintf pretty well now... But I have a question about example from www.php.net, about this section: ... $query = sprintf("INSERT INTO products (`name`, `description`, `user_id`) VALUES ('%s', '%s', %d)", mysql_real_escape_string($product_name, $link), mysql_real_escape_string($product_description, $link), $_POST['user_id']); ... With this code, it is taking the $product_name and $product_description and escaping it. But since I need to use these variables in further queries later on, within the same page... I need to have the variables 'raw', that way they don't get escaped twice. So my question to you, is if I escape the variables using mysql_real_escape_string, have I then changed the variables? Or am I only escaping the variables for this query, and leaving them 'raw'? Thanks! Link to comment https://forums.phpfreaks.com/topic/50406-sprintf-question/ Share on other sites More sharing options...
kenrbnsn Posted May 7, 2007 Share Posted May 7, 2007 The mysql_real_escape_string() function doesn't modify the values of the input variables, it just returns the new value. Ken Link to comment https://forums.phpfreaks.com/topic/50406-sprintf-question/#findComment-247578 Share on other sites More sharing options...
sasa Posted May 7, 2007 Share Posted May 7, 2007 try <?php mysql_connect('localhost','root',''); $a ='a\b'; echo mysql_real_escape_string($a); echo "\n<hr />\n"; echo $a; ?> Link to comment https://forums.phpfreaks.com/topic/50406-sprintf-question/#findComment-247583 Share on other sites More sharing options...
notepad Posted May 9, 2007 Author Share Posted May 9, 2007 Thanks for clearing that up... I just wanted to make sure I wasn't escaping the data twice. =) I do have one more question if I may, I am brand new to sprintf(), and I don't really understand the point of it. I am using it, because all of the examples on php.net use it... So I figure there is something to it, but I don't know what that "something" is. Could you explain the purpose of it? Thanks! Link to comment https://forums.phpfreaks.com/topic/50406-sprintf-question/#findComment-248729 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.