Reputation: 1
My website shows the following error when host updates the php version
Warning: preg_match(): No ending delimiter '^' found in
in the following code:
<?php
$mid_str = " and mid != '0' and ";
if($_REQUEST['search']){
mysql_select_db($database_myconn, $myconn);
$query_spages = "SELECT id, url, title, description, keywords, active, ip, catID, exp, pdate,
MATCH(title,description,keywords)
AGAINST ('$search_str' IN BOOLEAN MODE) AS score FROM pages
WHERE MATCH(title, description,keywords)
AGAINST ('$search_str' IN BOOLEAN MODE) " . $mid_str . " active = 'Yes' ORDER BY score DESC";
}else// not search fetch rand by catid
$query_spages = "SELECT * FROM pages where " . preg_match("^ and", "", $mid_str) . " active = 'Yes' and catID = '" . $_REQUEST['id'] . "' ORDER BY mid DESC";
mysql_select_db($database_myconn, $myconn);
$spages = mysql_query($query_spages, $myconn) or die(mysql_error());
//$row_spages = mysql_fetch_assoc($spages);
unset($settings);
$settings = mysql_fetch_assoc(mysql_query('select * from settings where id = 1',$myconn));
?>
Upvotes: 0
Views: 48
Reputation: 11
preg_match expects a start and an end of the regular expression.
For example preg_match("/^ and/", "", $mid_str)
.
In your case, ^
is taken as start delimiter but the regex does not end with ^
so you get an error. Start and end delimiter can be anything, but most likely /
is used to not clash with other specially treated characters.
Also, you probably mixed up preg_match
and preg_replace
. I think you want to preg_replace
here, p.e.
$query_spages = "SELECT * FROM pages where " . preg_replace("/^ and/", "", $mid_str) . " active = 'Yes' and catID = '" . $_REQUEST['id'] . "' ORDER BY mid DESC";
Upvotes: 1