PHP Corn Job not inserting into database

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tutu saint
    New Member
    • Jun 2011
    • 21

    PHP Corn Job not inserting into database

    Please help
    I have a php script that inserts current date and value into a table.
    The scripts work fine on my local system when run but trows up error when run as corn job in my cpanel.

    Code:
    <?php 
    # FileName="Connection_php_mysql.htm"
    # Type="MYSQL"
    # HTTP="true"
    $hostname_dbconnect = "localhost";
    $database_dbconnect = "database";
    $username_dbconnect = "username";
    $password_dbconnect = "password";
    
    $dbconnect = mysql_pconnect($hostname_dbconnect, $username_dbconnect, $password_dbconnect) or trigger_error(mysql_error(),E_USER_ERROR); 
    
    $date = date("Y-m-d");
    //$expiry = date ("Y-m-d", mktime (0,0,0,date("m")+12,(date("d")-1),date("Y")));
    
    $Date = curdate();
      $query = mysql_query("INSERT into counter (visit, date)
    					VALUES('0', '$Date')");
      if($query === false) 
        { 
            die("could not insert into database"); 
        } 
    	
    
    ?>
    ---------------Error Message -----------------

    could not insert into database

    ---------------End Error --------------------

    Please what could be the cause and possible solution
  • Luuk
    Recognized Expert Top Contributor
    • Mar 2012
    • 1043

    #2
    dont use 'mysql_pconnect ', its deprecated....

    put an 'echo $query' between line 18 and 19, and check that your SQL is correct, preferably by issueing the statment directly in the mysql-client.

    Comment

    • tutu saint
      New Member
      • Jun 2011
      • 21

      #3
      Hello Luuk,
      The file works perfectly when viewed with a browser. I mean, it inserts the date and value. But when created a corn job in cpanel with the is "/usr/local/bin/php -q /home/username/public_html/corn.php"

      It gives the below given error
      ---------------Error Message -----------------

      could not insert into database

      ---------------End Error --------------------

      Comment

      • Markus
        Recognized Expert Expert
        • Jun 2007
        • 6092

        #4
        In your query error handling, have a look at the output of
        Code:
        mysql_error()
        for some information pertaining to the error.

        Comment

        Working...