Page 1 of 1

How to increment username in php/mysql

Posted: Sat Aug 21, 2010 5:23 pm
by waqas87
hi ..
i am working on chat system ..there are two types of user one are register and other are guest and i have to add guest user..in to database as temporary so they can chat with each other the problem i am facing is with there names i want name like this (Guest1,Guest2,Guest3,Guest4,...so on..)..i am trying but it is not working on live server .. i have tested it on my local server using xampp server.. it worked but not on live server...

here is the code which i am using

Code: Select all

      if(isset($_SESSION['Guest']))

      {
   
      $_SESSION['Guest']=$_SESSION['Guest']+1;

      }

      else

      {
 
      $_SESSION['Guest']=1;

if(isset($_SESSION['Guest'])) { $_SESSION['Guest']=$_SESSION['Guest']+1; } else { $_SESSION['Guest']=1; }
and one more thing how i can delete Guest users who are not online..

Re: How to increment username in php/mysql

Posted: Sat Aug 21, 2010 7:49 pm
by MindOverBody
Advice is to use auto_increment ID on database table, and upon inserting new guest into db, check for biggest ID in table (do some google magic with MySQL 'MAX' keyword), bind 'Guest' word with MAX_ID+1 value, and that's it.
waqas87 wrote:and one more thing how i can delete Guest users who are not online..
Put 'last_activity' column in regarding database table which will be updated on every user/guest action, and on users 'login' check if there are users/guests with last activity that is by your opinion enoguh to declare someone 'offline'. Do time_now - last_activity difference to check it.

Re: How to increment username in php/mysql

Posted: Sat Aug 21, 2010 10:28 pm
by requinix
Don't bother with making sure the first guest is "Guest1" and the second is "Guest2". Just make them unique.

Insert the new row into the table and call them "Guest" + whatever the auto-incremented ID is.

Re: How to increment username in php/mysql

Posted: Sun Aug 22, 2010 1:52 am
by shawngoldw
The problem is that $_SESSION variables are different for each user. You can not just check if a session variable is set and increment it because each user has their own session variables. You need to use a database.

Shawn

Re: How to increment username in php/mysql

Posted: Sun Aug 22, 2010 6:17 pm
by waqas87
thx for reply guys ...guest problem solved ...how i can check guest is online or not i am using this

Code: Select all

					$delete = "DELETE FROM tbl_GuestUser WHERE GuestLogtime < NOW() - INTERVAL 300 SECOND";
					$record = mysql_query($delete) or die("DELETE SQL query failed");
to delete guest from database but this delete every user..i have one field as GuestLogtime which store Guest login time ....and the sub from current time ..