ChaosKnight Posted May 1, 2010 Share Posted May 1, 2010 Hi, I have a form that posts data to the database, so I'm very concerned about the security... My question is if this will work?: foreach ($_POST as $field => $value){ $$field = mysql_real_escape_string(strip_tags(trim($value))); } Any help will be greatly appreciated Link to comment https://forums.phpfreaks.com/topic/200364-escaping-strings/ Share on other sites More sharing options...
Ken2k7 Posted May 1, 2010 Share Posted May 1, 2010 What's $$field? You'll need to use $_POST[$field]. Link to comment https://forums.phpfreaks.com/topic/200364-escaping-strings/#findComment-1051491 Share on other sites More sharing options...
Daniel0 Posted May 1, 2010 Share Posted May 1, 2010 What's $$field? You'll need to use $_POST[$field]. http://dk2.php.net/manual/en/language.variables.variable.php As for the question, you don't need to use strip_tags when inserting into a database, and I would be wary about creating variables dynamically like that. You risk overriding other variables, which is why register globals is discouraged and deprecated. Link to comment https://forums.phpfreaks.com/topic/200364-escaping-strings/#findComment-1051492 Share on other sites More sharing options...
Ken2k7 Posted May 1, 2010 Share Posted May 1, 2010 What's $$field? You'll need to use $_POST[$field]. http://dk2.php.net/manual/en/language.variables.variable.php +1 Thank you. Link to comment https://forums.phpfreaks.com/topic/200364-escaping-strings/#findComment-1051493 Share on other sites More sharing options...
ChaosKnight Posted May 1, 2010 Author Share Posted May 1, 2010 So is this secure enough to go to the database?: $message = mysql_real_escape_string($_POST['message']); Link to comment https://forums.phpfreaks.com/topic/200364-escaping-strings/#findComment-1051572 Share on other sites More sharing options...
Daniel0 Posted May 1, 2010 Share Posted May 1, 2010 Assuming you're using MySQL, yes, that should be sufficient in most cases. Link to comment https://forums.phpfreaks.com/topic/200364-escaping-strings/#findComment-1051596 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.