Sytax Error - need help

Hi ,
I am new to php sa bare with me on this one

I got the following code that is supposed to catch search terms and insert them into a table,but i get a syntax error at line 13…Since i’m not so good with php,i’m asking your help to find the bug :slight_smile:

<?php

		$referrer = $_SERVER['HTTP_REFERER'];
		if(preg_match("/[\\.\\/](google|yahoo|bing|geegain|mywebsearch|ask|alltheweb)\\.[a-z\\.]{2,5}[\\/]/i",$referrer,$search_engine)){
		$referrer_query = parse_url($referrer);
		$referrer_query = $referrer_query["query"];
		$q = "[q|p]";
		preg_match("/".$q."=(.*?)&/",$referrer,$keywords);
		$keywords = urldecode($keywords[1]);
		
		if(isset($keywords)){
		
		$result = mysql_query ("SELECT number FROM keywords WHERE keywords="$keywords" limit 1") or die (mysql_error());
		$check = mysql_num_rows($result);
		
		if ($check=="0") {
		$new_row = mysql_query("INSERT INTO keywords VALUES ('1','$keywords')");
			}
		else {
		$update=mysql_query("UPDATE keywords SET number=number+1 WHERE keywords="$keywords"");

			}
		}

	}

?>

thank you.

Welcome to the SP forums.

Line 13 is

$result = mysql_query ("SELECT number FROM keywords WHERE keywords="$keywords" limit 1") or die (mysql_error());

and the syntax error is caused by the double quotes around $keywords. Use single quotes instead:

$result = mysql_query ("SELECT number FROM keywords WHERE keywords='$keywords' limit 1") or die (mysql_error());

thanks guido2004 !