Jump to content

mysql update current user


Wim77

Recommended Posts

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 />

Link to comment
https://forums.phpfreaks.com/topic/257570-mysql-update-current-user/
Share on other sites

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

 

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?

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'];

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.