This topic is locked

need help with query

6/9/2008 9:45:15 AM
PHPRunner General questions
E
echo author

i have setup fields in my table that logs when a user last logs in with time using this query:
[codebox]$query = "UPDATE user_usr SET logincounter_usr = logincounter_usr+1, lastlogin_usr = NOW() WHERE id_usr = ".$_SESSION["OwnerID"];

mysql_query($query) or die('Error, query failed');[/codebox]
that is working ok as an after successful login in global events. i then coded what i thought would work, but i can see the logic why it dosen't, but do not know how to accomplish. i have this code:
[codebox]//** Custom code ****

// put your custom code here

$query2 = mysql_query("SELECT `lastlogin_usr` FROM `user_usr` WHERE `id_usr`=".$_SESSION["OwnerID"]);

$row = mysql_fetch_array( $query2 );

$id = $row['lastlogin_usr'];
//** Display a message on the Web page ****
echo $_SESSION["UserID"]. " " . "You last logged in:" . "$id";[/codebox]
which i would like to display on the menu page. however, the results are returning the immediate login and not what was in the field before the latest login. how can i show when the user logged in previously before the table is updated by new login? many thanks

E
echo author 6/9/2008

any advice please? thanks

E
echo author 6/10/2008

why is no mods replying to this post? even if it is " no-one knows the answer". what kind of support is this?

J
Jane 6/10/2008

Hi,
it's very hard to understand what you're doing.

Where is this code placed: in the AfterSuccessfulLogin event, in the custom event or in another event?
Also I recommend you to use $_SESSION["UserID"] in the update SQL query:

global $conn;

$query = "UPDATE user_usr SET logincounter_usr = logincounter_usr+1, lastlogin_usr = NOW() WHERE loginname = '".$_SESSION["UserID"]."'";

db_exec($query,$conn);

E
echo author 6/10/2008

thanks very much for reply jane. the reason i use $_SESSION["OwnerID"] is that gives me a int result and $_SESSION["UserID"] gives me a name result. what i am trying to achieve is display the last date & time a user logged in.
i have placed:
[codebox]$query = "UPDATE user_usr SET logincounter_usr = logincounter_usr+1, lastlogin_usr = NOW() WHERE id_usr = ".$_SESSION["OwnerID"];

mysql_query($query) or die('Error, query failed');[/codebox]
i have placed that code in `AfterSuccessfulLogin` and
[codebox]//** Custom code ****

// put your custom code here

$query2 = mysql_query("SELECT `lastlogin_usr` FROM `user_usr` WHERE `id_usr`=".$_SESSION["OwnerID"]);

$row = mysql_fetch_array( $query2 );

$id = $row['lastlogin_usr'];
//** Display a message on the Web page ****
echo $_SESSION["UserID"]. " " . "You last logged in:" . "$id";[/codebox]
in `menu page - before process`
what is the correct way to setup this type of event?
thank you

J
Jane 6/10/2008

Hi,
your code looks correct.

Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.

E
echo author 6/12/2008

jane. any ideas on this yet? sent mail 2 days ago. thanks

E
echo author 6/12/2008

this is ridiculous. i sent details 2 days ago and posted follow up today and still no reply? come on guys, what's going on.

E
echo author 6/15/2008

{BUMP}

S
steveh 6/16/2008

They offer support on the product (and quite well I think), a lot of people are asking for free consultancy, which they seem to give more often than not as well, so a little patience?

W
wrjost 6/16/2008

Hi, folks,

can't put it any better than Steve - best support I'm getting after over 25 years in the business.
@echo: maybe they were just on a break - add up the first and last names of most supporters and then use your IT-skills to find out where they had a regular bank holiday on the 12th and an irregular one on the 13th... Plus the weekend
Hint: there are a lot of nations which celebrate Labor Day not on the first Monday in September, but rather on May 1st... And some of said nations have big military parades then (or: again?) ;-))))
So: give them a break - they deserve it!
A wise crack from Europe,

Wilfried
P.S.: Even when on holiday, they do work. I had an urgent ticket with support which "admin" answered - Saturday morning at 4 a.m. ... <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=30292&image=1&table=forumreplies' class='bbc_emoticon' alt=':o' />

mic'',) 6/16/2008

This is the best support I ever had, please give a little patience they have to study and find the best solution to our queries.

The best help we can give to them is our patience.
@echo put your head in the ICE BOX!! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=30294&image=1&table=forumreplies' class='bbc_emoticon' alt=':lol:' />

E
echo author 6/16/2008

ok guys, heres the deal. i haven't asked for any ''
i was asked to submit details to support and demo account, which i did. after 2 days i posted asking if any further information was available and no reply. if they are on holiday (which i agree, everyone needs a break) an automated mail could have been sent to my mail address saying this would be looked into when they return. problem solved. i would also like to add, that i use x-cart for other projects and there forum and support is second to none. this situation would have never been allowed to develop this far. after all, i am not asking for an elephants ear in a bun, but an answer to very probably a simple question.
@Miceiw

if this is the best support you have ever had, then i am very happy for you and can only conclude that this must be your main source of software. and as for the ice box, fair dues if you feel a cheap remark would help the situation. no problem and i am perfectly chilled and patient and if you feel that after 2 days with no answer this is inpatient, then fair enough and perhaps i should put my head [color=#FF0000]DEEPERin the ice box the longer it goes on?
@wrjost

if holidays were the case, then like most other support forums they normally send there customers a mail or place a post as a sticky on the forum saying they are closed from 23-25 for example. i am too busy to guess when a company has there holidays.
@Steve Hanselman

Please read my post above about
In closing, i wish you guys well and feel pleased that you are getting the support which can only say at best is adequate in my humble opinion. cheers

Sergey Kornilov admin 6/16/2008

echo,
I'm trying to locate your email. What's your name and email address?

E
echo author 6/16/2008

admin
i am trying to send the details via pm in the forum, but your pm is disabled. should i send them by mail? thanks

Sergey Kornilov admin 6/16/2008

Hi,

your code looks correct.

Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.

S
steveh 6/17/2008

We said it was more like consultancy as you want somebody to fix your code, this isn't a product bug and you've got your code in the right places, just that the code is wrong.
You've got to either have another field to store the last login, or to save the value before you update it into a global.
Think about it, after a good login you set the last_usrlogin field to now, then later in the menu you use this, it's going to be set to a few seconds ago, not last week.
So you either need to add a field to your table to hold the previous one, or to declare and load a global, use this in the menu and load it in after successful login? (Or any of a zillion other options, like maybe having an audit table and selecting the second most recent from there or some other way).

E
echo author 6/17/2008

steve. the code i posted is working at the moment in another project outside of phpr so i know the code is ok. it just isn't working in phpr, that is why i need product help. i already have lastlogin_usr in my table to store when a user last logged in. basically, the ideal way would be to put this code:[codebox]//** Custom code ****

// put your custom code here

$query2 = mysql_query("SELECT `lastlogin_usr` FROM `user_usr` WHERE `id_usr`=".$_SESSION["OwnerID"]);

$row = mysql_fetch_array( $query2 );

$id = $row['lastlogin_usr'];
//** Display a message on the Web page ****
echo $_SESSION["UserID"]. " " . "You last logged in:" . "$id";[/codebox] in 'after success login' and this code:[codebox]$query = "UPDATE user_usr SET logincounter_usr = logincounter_usr+1, lastlogin_usr = NOW() WHERE id_usr = ".$_SESSION["OwnerID"];

mysql_query($query) or die('Error, query failed');[/codebox] in the menu page, but this would cause header problems. is there a tut that describes how to achieve this kind of query within phpr? many thanks

J
Jane 6/17/2008

Hi,
you need to update `user_usr` table in the AfterSuccessfulLogin event and print `lastlogin_usr` field in the Menu page: Before process event.

E
echo author 6/18/2008

hello jane
thanks very much for reply. still not working. here is what i have in 'after successful login'[codebox]//** Custom code ****

// put your custom code here
$query = "UPDATE user_usr SET logincounter_usr = logincounter_usr+1, lastlogin_usr = NOW() WHERE id_usr = ".$_SESSION["OwnerID"];

mysql_query($query) or die('Error' . $query . 'query failed');[/codebox]
and in 'menu page:before process'[codebox]//** Custom code ****

// put your custom code here

$query2 = mysql_query("SELECT `lastlogin_usr` FROM `user_usr` WHERE `id_usr`=".$_SESSION["OwnerID"]);

$row = mysql_fetch_array( $query2 );

$id = $row['lastlogin_usr'];
//** Display a message on the Web page ****
echo $_SESSION["UserID"]. " " . "You last logged in:" . "$id";[/codebox]
where am i going wrong? thanks

J
Jane 6/18/2008

Please publish your project on Demo Account and send to support@xlinesoft.com a URL to your pages along with instructions on reproducing this error.

I'll find what's wrong with your project inspecting it at Demo account site.

E
echo author 6/19/2008

jane. found another way to achieve result. many thanks

W
wrjost 6/19/2008

jane. found another way to achieve result. many thanks


@echo: Would you care to share it with us?
Greetings,

W.

E
echo author 6/20/2008

@wrjost
certainly. what i did was as per the attached code. the only drawback to doing it this way, is it creates a problem if i want to put a redirect in event, causes header problems. but in my case, that wasn't required.
put this in 'After Successful Login'
[codebox]// Put your code here.

//** Custom code ****

// put your custom code here

$query2 = mysql_query("SELECT DATE_FORMAT(`lastlogin_usr`,'%d-%m-%Y %k:%i:%s') as lastlogin_usr FROM `user_usr` WHERE `id_usr`=".$_SESSION["OwnerID"]);

$row = mysql_fetch_array( $query2 );

$id = $row['lastlogin_usr'];

$_SESSION["idlogin"] = $id;

//** Display a message on the Web page ****
//** Custom code ****

// put your custom code here
global $conn;

$query = "UPDATE user_usr SET logincounter_usr = logincounter_usr+1, lastlogin_usr = NOW() WHERE id_usr = ".$_SESSION["OwnerID"];

db_exec($query,$conn);

return true;[/codebox]
then i just placed the session on the page where i want to display the message, in my case, the list page:[codebox]echo $_SESSION["UserID"]. " " . "You last logged in: " . $_SESSION["idlogin"];[/codebox]
now this may not be the correct way to code this, but i wasn't getting anywhere any other route, so if this works for me. great.
hope it helps someone else. cheers