Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I check an input against prohibited words in MySQL database?

Tags:

php

mysql

Hypothetically, if I didn't want to allow the word "douche" anywhere in a username and I have a table in my database with all of the prohibited words...

$q = "SELECT * FROM restrictions WHERE prohibited LIKE '%username%'";
$r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));

if (mysqli_num_rows($r) !== 0)
{
//username is prohibited
echo "invalid";
}
else
{
...etc

The problem is that I don't know how to execute a query that would pick up partial matches (ie. Jdoucher, or douchebag4). The %username% part is obviously wrong, I know. Does anyone know how to do this? Is it even possible? Thanks.

like image 571
David Avatar asked Dec 01 '25 05:12

David


1 Answers

select *
    from restrictions 
    where locate(prohibited, @username) <> 0
like image 91
Joe Stefanelli Avatar answered Dec 03 '25 17:12

Joe Stefanelli