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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Checking Amount Of Logins

    I have the following which works fine basically it gives me the details of the last time a member in my database logged in...

    PHP Code:
    mysql_query("UPDATE tblmembers SET loginDateTime = NOW(), MemberApproved='A' WHERE ID = '".$_SESSION['mid']."'"); 
    At the moment this just updates the last loginDateTime, I want to tally the loginDateTimes so I'm thinking the easiest way to do this would be to create another table called 'tbllogins' and then enter the Members User ID and loginDateTime... I'm just not sure what I need to put to make it enter the correct user id?

  • #2
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Simply add 'memberID' to your table 'tblmembers' and run the query:

    PHP Code:
    mysql_query("UPDATE tblmembers SET loginDateTime = NOW(), MemberApproved='A', memberID = {$_SESSION['mid']} WHERE ID = '".$_SESSION['mid']."'"); 
    This way you will not have to create a new table but all your data collected so far will have a blank field for the member ID.

    Does this help?

    D.
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    If you're running a tally then each time will be an insert not an update, so it will get the correct member id because you told it what the member id was.

    so it would look something like

    PHP Code:
    mysql_query("INSERT INTO tblLogins (mid, loginDateTime) VALUES({$_SESSION['mid']}, NOW()"); 

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Hey Nancy yea that's why I was thinking I would need a sepearte table because it's going to get quite large as the member's login, would you agree?

  • #5
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    Yes it will get huge if you have a lot of members logging in a lot, is that a problem?
    If you just want to keep track of the last date they logged in and the total number of times they've logged in then you just need to add an int field to their member record and increment it each time they log in.

    eg.

    PHP Code:
    mysql_query("UPDATE tblmembers SET loginDateTime = NOW(), MemberApproved='A', num_of_logins = num_of_logins +1 WHERE ID = '".$_SESSION['mid']."'"); 

  • #6
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    ahhhhh that's kind of brilliant! i liek that idea much better... the only thing is (and tell me if this could work without having to make another table) is i want to be able to search specifically by months, say like most active member in 'June' for example... would it work like this?

  • #7
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    The proposed solution will only record the last time a member has logged in.

    You could create a separate table for total logins and this table could be searched for specific timeframes (June etc) and you can gather information on each members log activity that way. This table will get very large though so bear it in mind.

    Missed the 'update' statement rather than 'insert' in my first reply. Sorry about that!

    D.
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com

  • #8
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ok well I tried this... But nothing happened... the first query works still, but the secon doesn't get entered into the table...

    PHP Code:
    mysql_query("UPDATE tblmembers SET loginDateTime = NOW(), MemberApproved='A' WHERE ID = '".$_SESSION['mid']."'");
            
    mysql_query("INSERT INTO tbllogins (MembersID, loginDate) VALUES({$_SESSION['mid']}, NOW()"); 

  • #9
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Can you display the error you get if one exists?
    What fields are in tbllogins?
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com

  • #10
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Just two MembersID and loginDate... I made MembersID an index also... And no error appears which is wierd too...

  • #11
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Try running an if else statement and place the mysql_error() in the else part. If the if (mysql_query) fails you should see the problem with printing out mysql_error

    D.
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com

  • #12
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Still no error It's like it just ignores that line completely...

  • #13
    Regular Coder
    Join Date
    Jun 2007
    Location
    N. Ireland
    Posts
    351
    Thanks
    16
    Thanked 4 Times in 4 Posts
    Can you post the entire PHP code around the MYSQL please?
    Daemonkin.
    If this was helpful, please add to my reputation
    Thousand Sons - Freelance Web Developer - ninetyonedegrees.com

  • #14
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    add or die(mysql_error()) after the second query
    eg.

    PHP Code:
     mysql_query("INSERT INTO tbllogins (MembersID, loginDate) VALUES({$_SESSION['mid']}, NOW()") or die(mysql_error()); 
    Also - is $_SESSION['mid'] and integer? I assumed it was but if its not then it needs to be quoted

  • #15
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Ok here is the code...

    PHP Code:
    $query "select * from tblmembers where UserName='" $_SESSION['strLoginName'] . "' AND Password='" $strPassword "'";
        
    $query .= "AND (MemberApproved='A' OR MemberApproved='N')";
        
    $rs mysql_query($query);
        
        if(!
    $rs)
        {
            
    mysql_close($dbConnection);
            die(
    "Failed to extract member information into database table - tblMembers: " mysql_error());
            exit();
        }    
        
        if(
    mysql_num_rows($rs) == 0)
        {
            
    //the user cannot be found - close the database connection and redirect
            
    mysql_close($dbConnection);
            
    header("location:error.php?error=loginfailure");
            exit();
        }
        
        else
        {
            
    //the user can be found.  Authenticate and redirect
            
    $_SESSION['firstName'] = mysql_result($rs,0,"FirstName");
            
    $_SESSION['mid'] = mysql_result($rs,0,"ID");
            
    $_SESSION['blnUserLoggedIn'] = true;

    //get Info
    $repNBR mysql_result($rs,0,"rep_NBR");

       
    $repInfo mysql_query("SELECT * FROM `tblrepresentatives` WHERE `rep_NBR`='$repNBR'");
       
    $rep mysql_fetch_array($repInfo);

                   
    $_SESSION['rep'] = $rep['rep_Firstname']." ".$rep['rep_Lastname'];

            
    mysql_query("UPDATE tblmembers SET loginDateTime = NOW(), MemberApproved='A' WHERE ID = '".$_SESSION['mid']."'");
            
    mysql_query("INSERT INTO tbllogins (MembersID, loginDate) VALUES({$_SESSION['mid']}, NOW()"); 
            
            
    closeDatabase($rs$dbConnection);
            
    header("location:home.php");         
            
        }
    }
    ?> 
    Yea that SESSION is the members ID so it's just a unique number in the database... Also when I added the or die, it gave me the following

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
    Which makes no sense on line one which has never been changed I have <?php
    Last edited by tomyknoker; 07-16-2007 at 03:49 PM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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