?
Solved

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

Posted on 2011-03-17
2
Medium Priority
?
230 Views
Last Modified: 2012-05-11
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.

Thanks
0
Comment
Question by:ipconfig610
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 27

Accepted Solution

by:
Lukasz Chmielewski earned 2000 total points
ID: 35159310
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

if($islogged){
 $query = "update users set logins = logins + 1 where $login = '$userlogin'";
 $result = mysql_query($query) or die(mysql_error());;
}
0
 
LVL 1

Expert Comment

by:bluedevil9
ID: 35159340
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.
0

Featured Post

Get MongoDB database support online, now!

At Percona’s web store you can order your MongoDB database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card. Handle your MongoDB database support now!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question