Copy link to clipboard
Copied
Hello,
The code below allows the user to add a table to a database, the name of which is chosen by the user. It works great. However, I would like to block the user from adding tables with pornographic names like "sex," "porn," etc. How could I do this?
Thanks in advance,
John
<?php
if (isset($_POST['name']) && !empty($_POST['name'])) {
mysql_connect("mysqlv3", "username", "database") or
die(mysql_error());
mysql_select_db("sand2") or die(mysql_error());
$table = mysql_real_escape_string($_POST['name']);
$query = "CREATE TABLE `$table` (id INT(11) NOT NULL auto_increment, site VARCHAR(150) NOT NULL, votes_up BIGINT(9) NOT NULL, votes_down BIGINT(9) NOT NULL, PRIMARY KEY(id), UNIQUE (site))";
$result = mysql_query($query) or die(mysql_error());
}
?>
Copy link to clipboard
Copied
populate your db with table names of unwanted words yourself so user can not create them themselves or use one of the many scripts found via google search term php block words.
Copy link to clipboard
Copied
I definitely don't want the terms in my database, either. I think I'll need to use a script. Maybe an If statement or something.