Need PHP Help - Issue with Script for Keyword Tracking

Discussion in 'PHP' started by madazaar, Feb 25, 2008.

  1. #1
    Could really use some help as I'm completely new to PHP. I recently put this into place (it's the keyword tracking script from oooff . com) and I'm having an issue with one particular part dealing with the SQL database. Here's the code:

    <?
    //connecting to the database we setup
     $dbh=mysql_connect ("localhost", "login", "password") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("db name");
    
    // Server variables
    $ip = $_SERVER[’REMOTE_ADDR’];
    $referer = $_SERVER[’HTTP_REFERER’];
    $useragent = $_SERVER[’HTTP_USER_AGENT’];
    
    // capturing data we passed in the url
    //ie. http://domain.com/page.php?k=my+keyword&s=yahoo
    // I’ve added the engine the click is coming from as
    // I’m starting to branch out to other engines now
    $keyword = trim($_GET[’k']);
    $source = trim($_GET[’s’]);
    
    $sql = “INSERT INTO `clicks` (`keyword`,`source`,`ip`,`referer`,`useragent`,`time`,`site`) VALUES (’$keyword’,'$source’,'$ip’,'$referer’,'$useragent’,NOW(),’$site’)”;
    mysql_query($sql);
    
    $id = mysql_insert_id();
    
    ?>
    PHP:
    When I check my site I get the following error:
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ']' in /home/madazaar/public_html/freebabyoffers/tracking.php on line 18

    Line 18 is the line "Insert Into" line. I've messed with changing the quotes and can't find what the problem is. I'm also not confident that the quotes in these two lines are correct either:

    $keyword = trim($_GET[’k']);
    $source = trim($_GET[’s’]);
    PHP:
    Does anyone have any experience putting this script into place? I would really appreciate the help.

    Thanks!
     
    madazaar, Feb 25, 2008 IP
  2. bpasc95

    bpasc95 Active Member

    Messages:
    196
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    70
    #2
    Try this instead (Changed quotes and apostrophe's):

    <?
    //connecting to the database we setup
    $dbh=mysql_connect ("localhost", "login", "password") or die ('I cannot connect to the database because: ' . mysql_error());
    mysql_select_db ("db name");
    
    // Server variables
    $ip = $_SERVER['REMOTE_ADDR'];
    $referer = $_SERVER['HTTP_REFERER'];
    $useragent = $_SERVER['HTTP_USER_AGENT'];
    
    // capturing data we passed in the url
    // ie. http://domain.com/page.php?k=my+keyword&s=yahoo
    // I've added the engine the click is coming from as
    // I'm starting to branch out to other engines now
    $keyword = trim($_GET['k']);
    $source = trim($_GET['s']);
    
    $sql = "INSERT INTO 'clicks' ('keyword','source','ip','referer','useragent','time','site') VALUES ('$keyword','$source','$ip','$referer','$useragent',NOW(),'$site')";
    mysql_query($sql);
    
    $id = mysql_insert_id();
    
    ?> 
    PHP:
    -Bing
     
    bpasc95, Feb 26, 2008 IP
  3. madazaar

    madazaar Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Well, I think that might have done the trick! I'm not seeing the errors anymore! :)

    Thanks for your help. I really appreciate it!
     
    madazaar, Feb 26, 2008 IP