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 4 of 4
  1. #1
    axd
    axd is offline
    New Coder
    Join Date
    Mar 2009
    Location
    Leeds, UK
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Problems with my syntax

    Hello, kinda new to PHP and MYSQL, I have created a website through using tutorials. It works well but i need to edit a small section of code to allow for editing users, and am not sure of the correct mysql syntax (or php, tbh i am not sure which category this falls under, so if it should be in php I apologise in advance). On with the issue....



    I have this code....
    Code:
    /**
        * procDeleteInactive - All inactive users are deleted from
        * the database, not including administrators. Inactivity
        * is defined by the number of days specified that have
        * gone by that the user has not logged in.
        */
       function procDeleteInactive(){
          global $session, $database;
          $inact_time = $session->time - $_POST['inactdays']*24*60*60;
          $q = "DELETE FROM ".TBL_USERS." WHERE timestamp < $inact_time "
              ."AND userlevel != ".ADMIN_LEVEL;
          $database->query($q);
          header("Location: ".$session->referrer);

    I am trying to add another user level to be ignored when deleting inactive users. The user level is called PREMIUM_LEVEL, but i am unsure of the correct way to add it after the

    Code:
      $q = "DELETE FROM ".TBL_USERS." WHERE timestamp < $inact_time "
              ."AND userlevel != ".ADMIN_LEVEL;
    I have the PREMIUM_LEVEL etc all set up, i just need advice on adding it to the end of this statement, so it ignores both ADMIN_LEVEL and PREMIUM_LEVEL


    Many thanks to all who reply

    Dan

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    Just tack it on:
    Code:
    $q = "DELETE FROM ".TBL_USERS." WHERE timestamp < $inact_time "
              ." AND userlevel != ".ADMIN_LEVEL
              ." AND userlevel != ".PREMIUM_LEVEL;
    Or you could get a tiny bit more sophisticated:
    Code:
    $q = "DELETE FROM ".TBL_USERS." WHERE timestamp < $inact_time "
              ." AND userlevel NOT IN (" . ADMIN_LEVEL . "," . PREMIUM_LEVEL . ")";
    I have to ask: What format are you using for $inact_time???

    Since you don't have apostrophes around that value, it needs to be in the form YYYYMMDDhhmmss *as a number*. Is that what you have? (The hhmmss is optional.)

    Don't forget to leave a space before the keyword AND! I almost missed that.

    Hey...I'm NOT a PHP person. How come you don't need the dollar sign in front of ADMIN_LEVEL and PREMIUM_LEVEL????

  • #3
    axd
    axd is offline
    New Coder
    Join Date
    Mar 2009
    Location
    Leeds, UK
    Posts
    32
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Hi and thanks for the swift reply.

    Theres a couple of lines just above that that i didnt paste in, i think i just pasted the end to show you what i needed.

    I am not too sure on code myself, but i think heres where it states how long "inactive" is by the 24*60*60 multiplied by the amount of days selected from the main admin page from a drop down menu, and then deleted respectivley

    Code:
    function procDeleteInactive(){
          global $session, $database;
          $inact_time = $session->time - $_POST['inactdays']*24*60*60;
          $q = "DELETE FROM ".TBL_USERS." WHERE timestamp < $inact_time "
              ."AND userlevel != ".ADMIN_LEVEL;
          $database->query($q);
          header("Location: ".$session->referrer);
    I think the ADMIN_LEVEL is a function defined earlier in the php, maybe why there is no $dollar sign there

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,561
    Thanks
    80
    Thanked 4,496 Times in 4,460 Posts
    Well, it would be a good idea to DEBUG.

    echo or print your $q value to the screen, to see exactly what the actual query given to the DB is going to be.


  •  

    Posting Permissions

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