Wim77 Posted February 22, 2012 Share Posted February 22, 2012 Hey I have a question im making a script to update the current user that is logged on now i have the script that he update all the users but i want that the user that run the script only get the update i know that i have to change something at : WHERE id != '0'"); but what ? and i think i need to add something that he knows who the current user id ? Can someone help me with this ?? <?php include_once("GameEngine/Account.php"); mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS); mysql_select_db(SQL_DB); mysql_query("UPDATE ".TB_PREFIX."users SET cp = cp + 1500 WHERE id != '0'"); echo "Done. 1500 Cp has been added"; mysql_close(); ?> <br /> Quote Link to comment https://forums.phpfreaks.com/topic/257570-mysql-update-current-user/ Share on other sites More sharing options...
Dhanus Posted February 22, 2012 Share Posted February 22, 2012 Hi, Wim77 I am not sure how the user authentication works in your project, but I will assume the ID of the user is stored in S_SESSION['userId']. So, feel free to change that to whatever identification method you have for your users. Then I would do this: <?php include_once("GameEngine/Account.php"); mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS); mysql_select_db(SQL_DB); $userId = (int) $_SESSION['userId']; mysql_query("UPDATE ".TB_PREFIX."users SET cp = cp + 1500 WHERE id = '$userId'"); echo "Done. 1500 Cp has been added"; mysql_close(); ?> If you do not know how users are identified within the script, please post the GameEngine/Account.php file contents Quote Link to comment https://forums.phpfreaks.com/topic/257570-mysql-update-current-user/#findComment-1320211 Share on other sites More sharing options...
AyKay47 Posted February 23, 2012 Share Posted February 23, 2012 and i think i need to add something that he knows who the current user id ? Couple of questions: Are you using sessions at all to store the users id? Do you have a auto_increment primary key set up in your database that would be the users id? Quote Link to comment https://forums.phpfreaks.com/topic/257570-mysql-update-current-user/#findComment-1320289 Share on other sites More sharing options...
Wim77 Posted February 23, 2012 Author Share Posted February 23, 2012 Hey Thanx for the reply , for me everything is new , i know a little bit but i am learning Now i have see below in the echo i see the username that is logged on but do i make the mistake in : 150 WHERE id='".$currentUID."'"); i see the username in a echo but he doesnt want to update the user itself so i can see in the echo that the user TEST is logged in and now i want to update the user does i do something wrong with the .$currentUID. ?? and to the questen Yes i have : Do you have a auto_increment primary key set up in your database that would be the users id? and question : Are you using sessions at all to store the users id? Yes i use include_once("GameEngine/Account.php"); mysql_connect(SQL_SERVER, SQL_USER, SQL_PASS); mysql_select_db(SQL_DB); $currentUID =$CURUSER["uid"]; // The ID of the user that you want to work with mysql_query("UPDATE ".TB_PREFIX."users SET gold = gold + 150 WHERE id='".$currentUID."'"); session_start(); echo $_SESSION['username']; Quote Link to comment https://forums.phpfreaks.com/topic/257570-mysql-update-current-user/#findComment-1320495 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.