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 6 of 6
  1. #1
    New Coder
    Join Date
    Dec 2008
    Posts
    14
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question MYSQL/PHP Update Problem

    Hello,

    I am currently making a script for a bit of fun and have got stuck at a certain point. My script is a date thing that works with php and mysql. It runs by a cron job that I have setup. Below you can see the two different files. In the table in the mysql database, there are just 3 fields. Day, Month and Year.

    Cron Job File

    PHP Code:
    <?

    include("include/db.php");
    include(
    "include/config.php");
    include(
    "include/functions.php");

    ?>

    <?

    $query 
    = ("SELECT * FROM Date");
    $row = (mysql_fetch_array(mysql_query($query)));

    $day $row['Day'];
    $month $row['Month'];
    $year $row['Year'];

    ?>

    <?

    $date 
    gamedate($day$month$year)

    ?>

    <?

    mysql_query
    ($date);

    ?>
    Function File

    PHP Code:
    <? function gamedate($day$month$year) {
        
        if (
    $day == "31") {
        
        return (
    $date = ("UPDATE Date SET Day = 1 AND SET Month = Month + 1"));
        
        } elseif (
    $month == "12" && $day == "31") {
        
        return (
    $date = ("UPDATE Date SET Day = 1 AND SET Month = 1 AND SET Year = Year + 1"));
        
        } elseif (
    $month == "2" && $day == "28") {
        
        return (
    $date = ("UPDATE Date SET Day = 1 AND SET Month = Month + 1"));
        
        } elseif (
    $month == "4" && $day == "30") {
        
        return (
    $date = ("UPDATE Date SET Day = 1 AND SET Month = Month + 1"));
        
        } elseif (
    $month == "6" && $day == "30") {
        
        return (
    $date = ("UPDATE Date SET Day = 1 AND SET Month = Month + 1"));
        
        } elseif (
    $month == "9" && $day == "30") {
        
        return (
    $date = ("UPDATE Date SET Day = 1 AND SET Month = Month + 1"));
        
        } elseif (
    $month == "11" && $day == "30") {
        
        return (
    $date = ("UPDATE Date SET Day = 1 AND SET Month = Month + 1"));
        
        } else {
        
        return (
    $date = ("UPDATE Date SET Day = Day + 1"));
        
        }
        
    }

    ?>
    I am currently running the cron every minute to test it but it gets stuck at 31/1/2000

    It should change to 1/2/2000 but it does not seem to want to do it and I cannot see anything wrong with it.

    Any help would be much appreciated.

    Thanks,

    Ryan
    Last edited by ryanhami; 07-07-2011 at 04:08 PM.

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    If you improve your code to check to make sure your query works, you'll see the error.

    PHP Code:
    $result mysql_query($date);
    if (!
    $result)
    {
        die(
    "Query Error! query: $date<br>Error:".mysql_error());

    Your UPDATE query is bad syntax; it should be UPDATE table SET column1 = value, column2 = value WHERE column3 = value

  • #3
    New Coder
    Join Date
    Dec 2008
    Posts
    14
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks for the response. Where will that error be shown if its running as a cron job?

  • #4
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Quote Originally Posted by ryanhami View Post
    Thanks for the response. Where will that error be shown if its running as a cron job?
    Good point, you'll miss it with just an echo. Write it to a log file instead of echoing it.

    But really, while writing your script, why are you messing with CRON too? Get the thing working outside of CRON first, then schedule it. But I believe fully in good logging so I would log errors 100% of the time.

  • Users who have thanked Fumigator for this post:

    ryanhami (07-06-2011)

  • #5
    New Coder
    Join Date
    Dec 2008
    Posts
    14
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Got it working now, thanks for the help Fumigator
    Last edited by ryanhami; 07-06-2011 at 04:53 PM.

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,851
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    UPDATE Date SET Day = '1', SET Month = Month + 1
    Check the manual (http://dev.mysql.com/doc/refman/5.0/en/update.html) for the right syntax!
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    ryanhami (07-06-2011)


  •  

    Posting Permissions

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