Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Making changes to a database on a chosen time

    Hi i was wondering if there was a guide to making something change in a database on a certain time of the day, What i want to happen is that a user will start with 1 of something but every 15mins i want this to add 1 to what the user already has E.g. :
    Lets say the time was 12:00pm
    points = 1
    and then at every 15 min intervals it would increase by 1
    (12:15pm)
    points = 2
    (12:30pm)
    points = 3
    (.... 2:00pm)
    points = 9
    And so on

    Any links to guides on how to do this would be helpful

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Google for "cron job"

  • #3
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Is there another way i can make the points increment every 15 mins, the cron job isnt working it keeps saying " permission denied " so i tryed changing chmod but still didnt work

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    As an alternative to a cron job(which should the the first choice), when the user logs in you could calculate the time since the last login and update the database accordingly.

  • #5
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i do think that a cron job would be the best, Because im expecting alot of users and each user is going to be able to see another users points. ill post what i did (when making a cron job) and what it tells me maybe someone can help me get it right lol

    EDIT Ok sorry lol i seem to have missed something in the address when making the cron ill tell you if it works this time
    Last edited by 2y2d; 08-12-2007 at 09:10 PM.

  • #6
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Heres what i got when it should have runned test.pl.

    nice: /home/sites/*****/******/test.pl.: Permission denied

    Contents of test.pl.
    PHP Code:
    <?php
    $host
    ="localhost"// Host name 
    $username="*****"// Mysql username 
    $password="****"// Mysql password 
    $db_name="*****"// Database name 
    $tbl_name="MainT"// Table name 

    mysql_connect("$host""$username""$password")or die("cannot connect"); 
    mysql_select_db("$db_name")or die("cannot select DB");
    $sql 'UPDATE `MainT` SET `Points` =  'Points 1
            . ' 
    ;
    ?>

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Well, the filename is wrong, you have a syntax error(see below), and the permissions of the file are wrong(what are they?). Does your user own the file, and have access to run cron jobs?
    PHP Code:
    $sql 'UPDATE `MainT` SET `Points` =  `Points` + 1'// Might need a WHERE clause depending on MySQL versions(I think?) 

  • #8
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Renamed the test.pl. to test.php and ive set the permissions to 755 i also changed the query lol ill edit this post when i know if it works or not

    Edit ( what i got )=
    /home/sites/******/public_html/test.php: line 1: ?php: No such file or directory/home/sites/****/public_html/test.php: line 2: =localhost: command not found/home/sites/*****/public_html/test.php: line 2: //: is a directory/home/sites/****/public_html/test.php: line 3: =*****: command not found/home/sites/*****/public_html/test.php: line 3: //: is a directory/home/sites/*****/public_html/test.php: line 4: =******: command not found/home/sites******/public_html/test.php: line 4: //: is a directory/home/sites/****/public_html/test.php: line 5: =*****: command not found/home/sites/*****/public_html/test.php: line 5: //: is a directory/home/sites/*****/public_html/test.php: line 6: =MainT: command not found/home/sites/******/public_html/test.php: line 6: //: is a directory/home/sites/*****/public_html/test.php: line 8: syntax error near unexpected token `"$host",'/home/sites/*****/public_html/test.php: line 8: `mysql_connect("$host", "$username", "$password")or die("cannot connect"); '

    :S
    Last edited by 2y2d; 08-12-2007 at 09:42 PM.

  • #9
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i dont think its going to let me use php in the cron job :s

  • #10
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    It doesn't look like php is being called. Check out this link for some information on how to setup the cron job. Or use a search engine to find some more examples. You should move the file out of the public_html folder so it can't be accessed by everyone going to your site, too.

  • #11
    New Coder
    Join Date
    Aug 2007
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    still doesnt seem to work ive got it to open the correct file and all i dont get the permissions denied anymore what i do get now is that the file to open that has the php in it doesnt exist but it is there and the path i made absolute lol ill just have to keep trying lol once i get sorted and running ill post how i did it in the tutorials so that people know how to go about it


  •  

    Posting Permissions

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