SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 17/05/2019, 09:39 PM   #1
Coox
Little Clucker
 
Coox's Avatar
 
Join Date: Feb 2018
Posts: 13
Reputation: 0
Default [Help] MySQL Update

Hello, I am in need of a help so I'll get right to it. Well I started doing a Register&Login system for my gamemode from scratch and I INSERT password and all of the other variables once the player enters the password on the first dialog, I hash the password but leave other variables with 0 like death, score,age, etc.. So when a player enters his age I want to UPDATE the variable I inserted, everything goes well in the logs and things but my where id = %d is always 0.

Code:
cache_get_value_int(0, "ID", pInfo[playerid][ID]);
pInfo[playerid][Age] = strval(inputtext);
new DB_Query[256];
mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `PLAYERS` SET `AGE` = %d WHERE `ID` = %d LIMIT 1",pInfo[playerid][Age], pInfo[playerid][ID]);
mysql_tquery(Database, DB_Query);
And the following is the mysql log:

Code:
[11:19:58] [DEBUG] mysql_format(1, 0x04908840, 256, "UPDATE `PLAYERS` SET `AGE` = %d WHERE `ID` = %d LIMIT 1")
[11:19:58] [DEBUG] mysql_format: return value: '54'
[11:19:58] [DEBUG] mysql_tquery(1, "UPDATE `PLAYERS` SET `AGE` = 23 WHERE `ID` = 0 LIMIT 1", "", "")
[11:19:58] [DEBUG] CCallback::Create(amx=0x1e3a610, name='', format='', params=0x490882c, param_offset=5)
[11:19:58] [DEBUG] CHandle::Execute(this=0x75a650, type=1, query=0x783bc8)
[11:19:58] [DEBUG] CHandle::Execute - return value: true
[11:19:58] [DEBUG] mysql_tquery: return value: '1'
[11:19:58] [DEBUG] CConnection::Execute(query=0x783bc8, this=0x25d0020, connection=0x764278)
[11:19:58] [DEBUG] CQuery::Execute(this=0x783bc8, connection=0x764278)
[11:19:58] [INFO] query "UPDATE `PLAYERS` SET `AGE` = 23 WHERE `ID` = 0 LIMIT 1" successfully executed within 0.375 milliseconds
Coox is offline   Reply With Quote
Old 18/05/2019, 07:51 AM   #2
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 553
Reputation: 90
Default Re: [Help] MySQL Update

You call `cache_get_value_int` function but do you execute a SELECT query before?

When a player registers, send an INSERT query and specify a callback in `mysql_tquery`. Retrieve generated value using `cache_insert_id` function and store in `pInfo[playerid][ID]`. You have to set `ID` as auto increment column by the way.
Calisthenics is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mysql Update Zeth Discussion 5 29/08/2017 02:19 AM
mysql update [rep] bugmenotlol Scripting Help 3 02/01/2017 07:15 PM
Update Mysql R6 to R39 Slawiii Scripting Help 5 10/11/2015 04:48 PM
MySQL R38 - UPDATE AndreOliveira Português/Portuguese 5 26/04/2014 05:04 PM
MySQL Update Marusa Scripting Help 3 04/03/2012 08:09 PM


All times are GMT. The time now is 06:52 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.