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

Link to comment
Share on other sites

 

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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.