• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

I need some PHP code that will READ a value in a MySQL database and UPDATE value by 1

I have a very simple web users database which a MySQL database called "users".  In the users database there is a table called "members" which stores usernames and passwords.  I added a new Field called "logins" so we could track the total number of logins by each user.

I need some PHP code that will increment the "logins" field each time a web user logins in.   Currently i have a checklogin.php file that registers the users session upon successful login.

1 Solution
Lukasz ChmielewskiCommented:
Let's assume $islogged is the boolean value for the user to check if is logged or not and $userlogin is user login stored in a session / cookie

 $query = "update users set logins = logins + 1 where $login = '$userlogin'";
 $result = mysql_query($query) or die(mysql_error());;
once the session is active, pull the "logins" value from the database of the particular user and increment the value and update the value using the update query.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to Squarespace.com and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now