replace the function_to_clean_value_for_sql into mysql_real_escape_string
and try not copy paste the codes, becouse most of the examples are untested.
The previous example is not correct in 100 %.
This might be a better way to build search terms:
<?php
function stripslashes2( $string ) {
if(get_magic_quotes_gpc()) {
return stripslashes($string);
} else {
return $string;
}
}
function mres($var)
{
return mysql_real_escape_string(stripslashes2($var));
}
if ( isset( $_POST['search'] ) ) {
$mainterm = str_replace( array( '\\' , "," , "." , "-" , "+" , "-" , "/" , "'" , '"' , "(" , ")"
) , " " , $_POST['search'] );
$search_terms = explode( ' ', $mainterm );
foreach( $search_terms as $term ) {
if ( strlen( trim( $term ) ) > 2 )
$where[] = sprintf( " product_name LIKE '%%%s%%' " , mres( $term ) );
}
}
$qry = "select * from product_table";
if ( !empty( $where ) )
$qry .= " WHERE " . implode( " OR " , $where );
print $qry; // test in phpmyadmin
?>