I'd just like to point out that using mysql_real_escape_string() will not prevent SQL injection attacks because there are no single quotes encasing its value. This means that we can still manipulate the query to whatever we'd like:
PHP Code:
$evil = ' WHERE id = 1';
$query = mysql_query('SELECT * FROM table'.mysql_real_escape_string($evil));
It's just as well MySQL's PHP interface does not support stacked queries (or as far as I know, at least), otherwise the attacker could wreak havoc with your tables:
PHP Code:
$evil = '; DROP TABLE table--';
$query = mysql_query('SELECT * FROM table'.mysql_real_escape_string($evil));
I'd personally do what K.wolf stated above, have another column stating the type of customer they are. However if you do want to do it this way, then validate the HTTP POST data with a pre-set list of known table names:
PHP Code:
$valid = array('A1', 'B2', 'C3');
if(!in_array($_POST['key'], $valid, TRUE))
{
die;
}
Bookmarks