dadamssg Posted March 14, 2009 Share Posted March 14, 2009 i want to create a function that cleans the values completely. rather than fooling with it for an hour and getting frustrated, i figure you guys could help me out in two seconds. i want it to do this mysqli_real_escape_string($cxn, strip_tags($_POST['whatever'])); where $cxn = mysqli_connect($host, $user,$passwd,$dbname) or die ("Couldn't connect to server."); is this close? function clean_data() { $cxn = mysqli_connect($host, $user,$passwd,$dbname) or die ("Couldn't connect to server."); mysqli_real_escape_string($cxn, strip_tags($variable)); } all the values that will go into it will be $_POSTs so i don't really know what to put for the $variable part, or if i need to put something inside the parenthesis when im defining the function basically i want to this $clean_password = clean_data($_POST['password']); Link to comment https://forums.phpfreaks.com/topic/149336-function-help/ Share on other sites More sharing options...
WolfRage Posted March 14, 2009 Share Posted March 14, 2009 <?php function clean_data($var) { $var=trim($var); if(get_magic_quotes_gpc()) { $var=stripslashes($var); } $var=htmlentities($var,ENT_QUOTES); return $var; } ?> However you might want a variation of this function that uses htmlspecialchars() for data such as email addresses, where they have special characters in them. Link to comment https://forums.phpfreaks.com/topic/149336-function-help/#findComment-784337 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.