We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,687 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Increasing an INT not working

Hello,

I have this code:

            mysql_query("UPDATE users SET BasicLevel = BasicLevel +1 where username='Admin'");

but its not increasing the integer. The field names are correct as well as the username. Can anyone help me? And yes, I am connected to the database.

3
Contributors
7
Replies
5 Hours
Discussion Span
7 Months Ago
Last Updated
8
Views
Yorkiebar14
Light Poster
48 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Well, there's nothing wrong with the basic syntax that I can see. Try `backticking` your fieldnames and tablenames, but I can't see that it would make a difference in this case.

diafol
Keep Smiling
Moderator
10,630 posts since Oct 2006
Reputation Points: 1,628
Solved Threads: 1,506
Skill Endorsements: 57

what is BasicLevel? is this set? is it a variable from the page? you may need a subquery in your SQL

"UPDATE users SET BasicLevel = (SELECT BasicLevel+1) where username='Admin'"
moneeshot
Light Poster
33 posts since Nov 2011
Reputation Points: 10
Solved Threads: 5
Skill Endorsements: 0

BasicLevel is the int in my mySql database I need to increase.

Yorkiebar14
Light Poster
48 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

you need to select it then first, did you try the code, works for me

moneeshot
Light Poster
33 posts since Nov 2011
Reputation Points: 10
Solved Threads: 5
Skill Endorsements: 0

It doesn't work for me... Any ideas?

Yorkiebar14
Light Poster
48 posts since Sep 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

thats a bit odd, did you test the code to make sure it works? BasicLevel = 6. hardcode it just to be sure. you could select the value, let php do the math then insert the value. thats the long road.

moneeshot
Light Poster
33 posts since Nov 2011
Reputation Points: 10
Solved Threads: 5
Skill Endorsements: 0

ok, try this, it's a little more structured

UPDATE users a
INNER JOIN users b ON a.username = b.username
SET a.BasicLevel = b.BasicLevel+1 where a.username='Admin'

if that don't work I have no idea? definately double check you column to make sure the datatype is int.

moneeshot
Light Poster
33 posts since Nov 2011
Reputation Points: 10
Solved Threads: 5
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page rendered in 0.3060 seconds using 2.71MB