SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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
    PHP Code:
    <?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.

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Welcome to the SP forums.

    Line 13 is
    PHP Code:
    $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:
    PHP Code:
    $result mysql_query ("SELECT number FROM keywords WHERE keywords='$keywords' limit 1") or die (mysql_error()); 

  3. #3
    SitePoint Member
    Join Date
    Feb 2012
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks guido2004 !


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •