SA-MP Forums Archive
MySQL does not update me - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL does not update me (/showthread.php?tid=642010)



MySQL does not update me - Swankeh - 23.09.2017

Hello, I have been testing to see if everything is going well, but at the moment of disconnecting I do not update the data of the player in the database. To see that the variables are fine I print them and for example I print them in one but when updating the table I do not update it stays in zero.

PHP Code:
    new DB_Query[256];
    
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `USUARIOS` SET `NIVEL` = '%d', `DINERO` = '%d', `ASESINATOS` = '%d', `MUERTES` = '%d' WHERE `ID` = '%d' LIMIT 1",
    
InfoU[playerid][pNivel], InfoU[playerid][pDinero], InfoU[playerid][pAsesinatos], InfoU[playerid][pMuertes], InfoU[playerid][ID]); 



Re: MySQL does not update me - BreakStore - 23.09.2017

Hello try this,

PHP Code:
new DB_Query[256]; 
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `USUARIOS` SET `NIVEL` = %d, `DINERO` = %d, `ASESINATOS` = %d, `MUERTES` = %d WHERE `ID` = %d LIMIT 1"
InfoU[playerid][pNivel], InfoU[playerid][pDinero], InfoU[playerid][pAsesinatos], InfoU[playerid][pMuertes], InfoU[playerid][ID]);
mysql_tquery(DatabaseDB_Query); 
EDIT: You don't forget the function mysql_tquery to save the data of player ?


Re: MySQL does not update me - whadez - 23.09.2017

Make sure you dont clear the InfoU array before saving the data.


Re: MySQL does not update me - Swankeh - 23.09.2017

Quote:
Originally Posted by BreakStore
View Post
Hello try this,

PHP Code:
new DB_Query[256]; 
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `USUARIOS` SET `NIVEL` = %d, `DINERO` = %d, `ASESINATOS` = %d, `MUERTES` = %d WHERE `ID` = %d LIMIT 1"
InfoU[playerid][pNivel], InfoU[playerid][pDinero], InfoU[playerid][pAsesinatos], InfoU[playerid][pMuertes], InfoU[playerid][ID]);
mysql_tquery(DatabaseDB_Query); 
EDIT: You don't forget the function mysql_tquery to save the data of player ?
Hello thanks for replying, if I have mysql_tquery I forgot to post it here, I tried it as you did the code and keep going with the same review the table and has it in 0, but when printing the value I print it in 1, I have it trying in several ways and not being updated.


PHP Code:
    mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `USUARIOS` SET `NIVEL` = %d, `DINERO` = %d, `ASESINATOS` = %d, `MUERTES` = %d WHERE `ID` = %d LIMIT 1",
    
InfoU[playerid][pNivel], InfoU[playerid][pDinero], InfoU[playerid][pAsesinatos], InfoU[playerid][pMuertes], InfoU[playerid][ID]);
    
mysql_tquery(DatabaseDB_Query);
    
printf("%d"InfoU[playerid][pNivel]); 
I give you the create table.

PHP Code:
mysql_tquery(Database"CREATE TABLE IF NOT EXISTS `USUARIOS` (`ID` int(11) NOT NULL AUTO_INCREMENT,`NOMBRE` varchar(24) NOT NULL,`CLAVE` char(65) NOT NULL,`SALT` char(11) NOT NULL,`NIVEL` mediumint(7), `ASESINATOS` mediumint(7), `DINERO` mediumint(7) NOT NULL DEFAULT '0',`MUERTES` mediumint(7) NOT NULL DEFAULT '0', PRIMARY KEY (`ID`), UNIQUE KEY `NOMBRE` (`NOMBRE`))"); 
The table if it is created, until the account of the player but what happens is that when disconnecting is not updated

I have tried since yesterday but I do not update anything.


Re: MySQL does not update me - whadez - 23.09.2017

Code:
printf("UPDATE `USUARIOS` SET `NIVEL` = '%d', `DINERO` = '%d', `ASESINATOS` = '%d', `MUERTES` = '%d' WHERE `ID` = '%d' LIMIT 1", InfoU[playerid][pNivel], InfoU[playerid][pDinero], InfoU[playerid][pAsesinatos], InfoU[playerid][pMuertes], InfoU[playerid][ID]); 

mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USUARIOS` SET `NIVEL` = '%d', `DINERO` = '%d', `ASESINATOS` = '%d', `MUERTES` = '%d' WHERE `ID` = '%d' LIMIT 1", 
InfoU[playerid][pNivel], InfoU[playerid][pDinero], InfoU[playerid][pAsesinatos], InfoU[playerid][pMuertes], InfoU[playerid][ID]); 
mysql_tquery(Database, DB_Query, "", "");
Send me the output message.


Re: MySQL does not update me - Swankeh - 23.09.2017

Ready I made it here is the message.

UPDATE `USUARIOS` SET `NIVEL` = '1', `DINERO` = '0', `ASESINATOS` = '0', `MUERTES` = '1' WHERE `ID` = '0' LIMIT 1

What you notice is that if you save the variable with the correct value in 1.
I put the code that you passed me.

PHP Code:
    printf("UPDATE `USUARIOS` SET `NIVEL` = '%d', `DINERO` = '%d', `ASESINATOS` = '%d', `MUERTES` = '%d' WHERE `ID` = '%d' LIMIT 1"InfoU[playerid][pNivel], InfoU[playerid][pDinero], InfoU[playerid][pAsesinatos], InfoU[playerid][pMuertes], InfoU[playerid][ID]);
    
mysql_format(DatabaseDB_Querysizeof(DB_Query), "UPDATE `USUARIOS` SET `NIVEL` = '%d', `DINERO` = '%d', `ASESINATOS` = '%d', `MUERTES` = '%d' WHERE `ID` = '%d' LIMIT 1",
    
InfoU[playerid][pNivel], InfoU[playerid][pDinero], InfoU[playerid][pAsesinatos], InfoU[playerid][pMuertes], InfoU[playerid][ID]);
    
mysql_tquery(DatabaseDB_Query""""); 
maybe it's problem with mysql_tquery? Or why do not you update it?

EDIT: If you need an image of my table, I'll give it to you.


Re: MySQL does not update me - Swankeh - 23.09.2017

Quote:
Originally Posted by whadez
View Post
Code:
printf("UPDATE `USUARIOS` SET `NIVEL` = '%d', `DINERO` = '%d', `ASESINATOS` = '%d', `MUERTES` = '%d' WHERE `ID` = '%d' LIMIT 1", InfoU[playerid][pNivel], InfoU[playerid][pDinero], InfoU[playerid][pAsesinatos], InfoU[playerid][pMuertes], InfoU[playerid][ID]); 

mysql_format(Database, DB_Query, sizeof(DB_Query), "UPDATE `USUARIOS` SET `NIVEL` = '%d', `DINERO` = '%d', `ASESINATOS` = '%d', `MUERTES` = '%d' WHERE `ID` = '%d' LIMIT 1", 
InfoU[playerid][pNivel], InfoU[playerid][pDinero], InfoU[playerid][pAsesinatos], InfoU[playerid][pMuertes], InfoU[playerid][ID]); 
mysql_tquery(Database, DB_Query, "", "");
Send me the output message.
Thanks to you I noticed the problem, in my table of users when you register you create the table with the unique ID, in the printf it gives me in 0 when it would have to be in 1.


Re: MySQL does not update me - whadez - 23.09.2017

Yes the ID column should be auto increment, no problem.