echoindia756 Posted July 5, 2008 Share Posted July 5, 2008 Hi there, I'm designing an online game website. I'm having a little trouble getting something to work right. You see players of the game can buy "credits", these allow them to buy things to further their rank etc and make them stronger than other players. But the problem i'm having is that when a player buys credits, it gives that player credits, but it also gives every other player in the database credits! So if one person buys 100 credits, every user in the database gets 100 credits. This is the code i'm using: mysql_query("UPDATE `game_planets` SET `belcredits`=`belcredits`+'100'"); How would I change that code so it only updates the person's credits who actually bought them? I was thinking of something like getting the username that the user used to login, or maybe somebody can think of a better way to solve this. Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/ Share on other sites More sharing options...
Juan Dela Cruz Posted July 5, 2008 Share Posted July 5, 2008 your update query will update all the records in your belcredits because you dont have any condition "where clause" that says what record to be updated Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582557 Share on other sites More sharing options...
echoindia756 Posted July 5, 2008 Author Share Posted July 5, 2008 your update query will update all the records in your belcredits because you dont have any condition "where clause" that says what record to be updated I tried a few Where Clause's, but what clause would I write so that it only updated the users credits that actually bought the credits? Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582562 Share on other sites More sharing options...
ryeman98 Posted July 5, 2008 Share Posted July 5, 2008 mysql_query("UPDATE `game_planets` SET `belcredits=belcredits+100"); Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582570 Share on other sites More sharing options...
echoindia756 Posted July 5, 2008 Author Share Posted July 5, 2008 mysql_query("UPDATE `game_planets` SET `belcredits=belcredits+100"); That doesn't have any where clause?? lol Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582575 Share on other sites More sharing options...
ryeman98 Posted July 6, 2008 Share Posted July 6, 2008 mysql_query("UPDATE `game_planets` SET `belcredits=belcredits+100"); That doesn't have any where clause?? lol Put one in, I don't know what your table looks like Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582581 Share on other sites More sharing options...
echoindia756 Posted July 6, 2008 Author Share Posted July 6, 2008 Is there no way I can tell the code to only update the person's belcredits who bought the credits? Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582590 Share on other sites More sharing options...
ryeman98 Posted July 6, 2008 Share Posted July 6, 2008 Is there no way I can tell the code to only update the person's belcredits who bought the credits? Are you serious? Get their ID or username or w/e and create a WHERE Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582592 Share on other sites More sharing options...
echoindia756 Posted July 6, 2008 Author Share Posted July 6, 2008 Yea, that would be the logical thing - but how do I get the user id, I mean, I know you use the SELECT command to get things but how do I tell the code to identify the current user and match it up with the data in the username's field? If I could do that, that would solve the problem! Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582605 Share on other sites More sharing options...
DarkWater Posted July 6, 2008 Share Posted July 6, 2008 You don't store the user ID in the session? Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582608 Share on other sites More sharing options...
DarkerAngel Posted July 6, 2008 Share Posted July 6, 2008 mysql_query("UPDATE `game_planets` SET `belcredits`=`belcredits`+100 WHERE `username`='username' LIMIT 1"); There is an example of how it would update only one record based on username being usersname though I highly suggest using an ID field and ID being a UNIQUE. Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582610 Share on other sites More sharing options...
echoindia756 Posted July 6, 2008 Author Share Posted July 6, 2008 mysql_query("UPDATE `game_planets` SET `belcredits`=`belcredits`+100 WHERE `username`='username' LIMIT 1"); There is an example of how it would update only one record based on username being usersname though I highly suggest using an ID field and ID being a UNIQUE. Thanks! I have an ID Field in the database called id_owner and another field with the name of the planet. So would this work? mysql_query("UPDATE `game_planets` SET `belcredits`=`belcredits`+100 WHERE `name`='id_owner' LIMIT 1"); Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582612 Share on other sites More sharing options...
DarkerAngel Posted July 6, 2008 Share Posted July 6, 2008 you have it backwards if the field is called `id_owner` it would be WHERE `id_owner`='[however you have your data set]' Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582622 Share on other sites More sharing options...
echoindia756 Posted July 6, 2008 Author Share Posted July 6, 2008 Ok, so when you say "=" does that mean that for example 1=1 or does it mean that they are in the same row of data? I'm just slightly confused! Thanks! Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582777 Share on other sites More sharing options...
echoindia756 Posted July 6, 2008 Author Share Posted July 6, 2008 You know how you said: it would be WHERE `id_owner`='[however you have your data set]' in the "however you have your data set", what exactly goes there? Another table? e.g `game_planets.id_owner`='game_planets.name' LIMIT 1"); This is puzzling me! Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582784 Share on other sites More sharing options...
echoindia756 Posted July 6, 2008 Author Share Posted July 6, 2008 bump Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582815 Share on other sites More sharing options...
echoindia756 Posted July 6, 2008 Author Share Posted July 6, 2008 Hi guys, Does anybody have any ideas? How about if I tried something with $_SESSION ? Would that work? For example, could I put WHERE game_planets.id_owner = $_SESSION['userid'] ? Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582850 Share on other sites More sharing options...
echoindia756 Posted July 6, 2008 Author Share Posted July 6, 2008 Please! Can anyone help me out? Link to comment https://forums.phpfreaks.com/topic/113388-question-about-changing-certain-data-in-mysql-database/#findComment-582905 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.