Debug help

Discussion in 'PHP' started by GrassR00ts, Mar 12, 2008.

  1. #1
    I wanted to see if any of you could see what I was doing wrong. I have been looking over this code for a while now and am completly stuck.

    Thanks

    <?
    //connecting to the database we setup
    define('DB_HOST', 'localhost');
    define('DB_NAME', 'dbname');
    define('DB_USERNAME', 'user');
    define('DB_PASSWORD', 'password');
    
    
    
    // Connect to the mysql database.
    $conn = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
    mysql_select_db(DB_NAME, $conn) or die(mysql_error());
    
    // 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:

     
    GrassR00ts, Mar 12, 2008 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    First off, replace <? with <?php.

    Then set these lines on top to see all errors that may occurred:
    
    error_reporting(E_ALL);
    ini_set('display_errors', '1');
    
    PHP:
    Then let MySQL tell you if there were any problems:
    
    mysql_query($sql) OR die(mysql_error());
    
    PHP:
    And last, use mysql_real_escape_string() on all variables that you put in your query string.
     
    nico_swd, Mar 12, 2008 IP
  3. GrassR00ts

    GrassR00ts Active Member

    Messages:
    614
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    58
    #3
    Hey Thanks for the help

    This is the error iam getting from the output

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''clicks' ('keyword','source','ip','referer','useragent','time','site') VALUES ('' at line 1
    PHP:
     
    GrassR00ts, Mar 12, 2008 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    The field and table names should not be enclosed in single quotes. Use either backticks, or nothing at all. (Note, values you're trying to insert SHOULD go enclosed in single quotes)
     
    nico_swd, Mar 12, 2008 IP
  5. GrassR00ts

    GrassR00ts Active Member

    Messages:
    614
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    58
    #5
    NICO


    YOU ROCK!

    anything I can do for you, a post on the network or anything
     
    GrassR00ts, Mar 12, 2008 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    What is "a post on the network"?
     
    nico_swd, Mar 12, 2008 IP
  7. GrassR00ts

    GrassR00ts Active Member

    Messages:
    614
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    58
    #7
    Check the link in my sig. I think the pr has dropped on a lot of the sites but it can get any site indexed in g very quickly. So if you have any new sites you want crawled its a great server. Whenever you want PM me an article or two to post.
     
    GrassR00ts, Mar 12, 2008 IP