Easy Syntax fix for LIKE query with variable
Posted: Wed Mar 11, 2009 11:27 pm
Hi All,
I am trying to create a simple word filter for my database and I am having trouble with a little bit of syntax that passes the variable into the LIKE query.
I have had a good look through some forums and found this solution but I can’t get it to work with my code.(http://www.phpfreaks.com/forums/index.p ... 601.0.html)
I think I am really close and it’s just a issue with the quotation marks.
any assistance would be greatly appreciated i have been searching for a solution for quite some time now.
Cheers,
Adam
I am trying to create a simple word filter for my database and I am having trouble with a little bit of syntax that passes the variable into the LIKE query.
I have had a good look through some forums and found this solution but I can’t get it to work with my code.(http://www.phpfreaks.com/forums/index.p ... 601.0.html)
I think I am really close and it’s just a issue with the quotation marks.
Code: Select all
$badwords=array("ass","babbi","penis");
foreach ($badwords as $badword)
{
//Delete query
$delete_sql = "DELETE FROM jos_facileforms_subrecords WHERE name LIKE \'%'.$badword.'%\' ";
// execute $delete_sql query and get result
$filter_sql_result = mysql_query($delete_sql,$connection)
or die(mysql_error());
echo $filter_sql_result;
} Cheers,
Adam