1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Hide link for 24 hours with PHP and MYSQL

Discussion in 'Programming' started by techboy, Oct 17, 2012.

  1. #1
    Hi all
    I have a big problem how to figure out why this will not work:

    I have a table to record all links that is clicked with a timestamp, but unfortantly I cant find the right code to use it:
    SEMrush
    My code is:
    <?php
    error_reporting(E_ALL ^ E_NOTICE);
    define('IN_SCRIPT',1);
    
    /* Get settings from the settings.php file */ 
    require 'settings.php';
    
    /* Get database connection from the database.php file */ 
    require 'database.php';
    
    
    /* Start user session or output an error */
    session_name('CCOUNT');
    if (!session_start()) {
        error('Cannot start a new PHP session. Please contact server administrator or webmaster!');
    }
    
    function curPageURL() {
     $pageURL = 'http';
     if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
     $pageURL .= "://";
     if ($_SERVER["SERVER_PORT"] != "80") {
      $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
     } else {
      $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
     }
     return $pageURL;
    }
    mysql_select_db("awc24h_links", $con);
    
    $user_id = $settings['user_id'];
    
    $result = mysql_query("Select * FROM Log where user_id='".$user_id."' AND url='".curPageURL()."' AND last_visit<'NOW() - INTERVAL 1 DAY'");
    
    if (mysql_num_rows($result)<1) {
        // $result = mysql_query("SELECT * FROM Click order by RANDOM() LIMIT 1");
        echo '24 hours have passed';
    } else {
        // header("Location: show.php");
        echo 'under 24 hours since last click <br><br>';
        echo curPageURL();
        echo '<br>';
        echo $user_id;
        echo NOW();
    }
    ?>
    Code (markup):
    Hope some one can help me figure this out
     
    techboy, Oct 17, 2012 IP
    SEMrush
  2. Wogan

    Wogan Peon

    Messages:
    81
    Likes Received:
    3
    Best Answers:
    2
    Trophy Points:
    0
    #2
    You've got some bad syntax here:

    $result = mysql_query("Select * FROM Log where user_id='".$user_id."' AND url='".curPageURL()."' AND last_visit<'NOW() - INTERVAL 1 DAY'");
    Try:

    $result = mysql_query("SELECT * FROM Log WHERE user_id = $user_id AND url = '".curPageURL()."' AND last_visit >= (DATE_SUB(CURDATE(), INTERVAL 1 DAY))");
    PHP:
     
    Wogan, Oct 17, 2012 IP
  3. techboy

    techboy Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #3
    It keep saying under 24 hours since last click:

    under 24 hours since last click:

    http://www.awc24h.com/click/installation/test.php
    installation
     
    techboy, Oct 17, 2012 IP
  4. techboy

    techboy Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #4
    Oh its not update timestamp
     
    techboy, Oct 17, 2012 IP
  5. techboy

    techboy Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    No still not working

    Timestamp is now :2012-10-17 02:41:28, means yester day
    today is 2012 -10 -18 should say over 24 hours since last click
     
    techboy, Oct 17, 2012 IP