How would you check in php that a string is a valid compatible column name for a sql statement? just a string match.
You can use the MySQL query as follows to get the fields from a particular table:
SHOW FIELDS FROM tbl_name
and then some simple PHP:
$string_to_check = 'sample';
$valid = false;
$q = mysql_query("SHOW FIELDS FROM tbl_name");
while($row = mysql_fetch_object($q)) {
if($row->Field == $string_to_check) {
$valid = true; break;
}
}
if($valid) {
echo "Field exists";
}