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
227 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 500 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

Is Your DevOps Pipeline Leaking?

Is your CI/CD pipeline a hodge-podge of randomly connected tools? You’ve likely got a tool to fix one problem & then a different tool to fix another, resulting in a cluster of tools with overlapping functionality. Learn how to optimize your pipeline with Gartner's recommendations

Question has a verified solution.

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

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…

690 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