Hello,
I have been using a function provided by laser to prep input and output into mysql.
//Input:
function prepIn($input) {
$input = trim($input);
if (!get_magic_quotes_gpc()) {
return addslashes($input);
}
return $input;
}
//I also use this to avoid pasted Word Chars in some areas:
$patterns = array ("/&/","/'/","/‘/","/’/","/\"/","/“/","/”/","/–/","/—/","/>/","/</");
$replacements = array ("&","'","'","'","\"","\"","\"","-","-",">","<");
//Ouput:
function prepOut($input) {
$input = stripslashes($input);
return htmlspecialchars($input);
}
{
Here's my question; I have several tables and some of them may have 20 columns so I find myself typing this alot:
SELECT stitle, sdescr.... from table
$row = mysql_fetch_assoc($rs);
$stitle = prepOut($row['stitle']);
$sdescr = prepOut($row['sdescr']);
I am hoping for a way to make that process a little more automated with a function. The variables are always named after the columns so I would like to be able to SELECT everything from a table, apply the prepOut function to that array, then setup a variable named after each column in the table while assigning the data to it. In other words; a function to do the above example without having to type:
$stitle = prepOut($row['stitle']);
$sdescr = prepOut($row['sdescr']);
..all the time.
Also,..some items are just integers and won't require being prepped, so would it be too much unnecessary overhead to be applying these functions to items where not needed?
Thanks for any advice.