I posted a problem with this a few weeks ago and decided to just leave it for the time being, but I've had to go back to it and after trying a new approach I still can't get the blasted thing to work. Below is the exact code I'm using in the file, which is being called to the main index with include_once(). When I use it I get an 'ending delimiter must not be alphanumeric or backslash' error six times (because $userkeywords has 6 elements) and at the end an 'empty regular expression' error. I dont understand this at all, can anyone help? Below is the code I am using:
<?php
$name = "$_COOKIE[name]";
$connection = mysql_connect($dbhost, $dbuser, $dbpass);
$db_name = "macklamm";
$table_name = "user_details";
$db = mysql_select_db($db_name, $connection);
$sql = "SELECT * FROM $table_name WHERE forename = '$name'";
$result = mysql_query($sql, $connection);
$matches = mysql_num_rows($result);
if ($matches != "1") {
echo "There was an error fetching your keywords. Please use the error report to report this to the Webmaster.";
}
else {
$sql = "SELECT keywords FROM $table_name WHERE forename = '$name'";
$result = mysql_query($sql, $connection);
$data = mysql_fetch_array($result);
$userkeywords = explode(",", $data[keywords]);
$userelements = sizeof($userkeywords);
$table_name = "consultations";
$sql = "SELECT keywords FROM $table_name WHERE state = '1'";
$result = mysql_query($sql, $connection);
$x = 0;
while ($data = mysql_fetch_array($result)) {
$conkeywords[$x] = "$data[keywords]";
$x++;
}
$conelements = sizeof($conkeywords);
$x = 0;
$matches = 0;
while ($x <= "$userelements") {
$searchkeyword = "$userkeywords[$x]";
$searchedkeyword = "$conkeywords[$x]";
if (preg_match($searchkeyword, $searchedkeyword)) {
$matches++;
}
else {
$matches = "$matches";
}
$x++;
}
echo "$matches";
}
?>