SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 06/01/2019, 08:24 PM   #1
enzulikeS
Big Clucker
 
Join Date: Jan 2018
Posts: 156
Reputation: 0
Default why doesnt update in database

Code:
CMD:getgift(playerid, params[]) {
	if(GiftBoxInfo[playerid][pGiftBoxOn] == 0) return SCM(playerid, -1, "Giftbox-ul nu este activ..");
    if(IsPlayerInRangeOfPoint(playerid, 5.0, GiftBoxInfo[playerid][pGiftBoxPosX], GiftBoxInfo[playerid][pGiftBoxPosY], GiftBoxInfo[playerid][pGiftBoxPosZ])) 
    {
		new rand = random(11); new zzString[128] = EOS;
		switch(rand) {
			case 0..5: {
				SCM(playerid, -1, "{008080}(GIFTBOX){FFFFFF}: Felicitari! Ai deschis giftbox-ul si ai castigat 10.000.000$.");
				GivePlayerCash(playerid, 10000000);
				Update(playerid, pCashx);
				mysql_format(SQL,zzString,sizeof(zzString),"UPDATE giftboxd SET `GiftBoxMoney`='%s'", GiftBoxInfo[playerid][pGiftBoxMoney]);
				mysql_tquery(SQL,zzString,"","");
			}

mysql_format(SQL,zzString,sizeof(zzString),"UPDATE giftboxd SET `GiftBoxMoney`='%s'", GiftBoxInfo[playerid][pGiftBoxMoney]);

this thing does not update in database, no errors in console..
enzulikeS is offline   Reply With Quote
Old 06/01/2019, 08:43 PM   #2
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,461
Reputation: 3206
Default Re: why doesnt update in database

There's no `WHERE`.
Y_Less is offline   Reply With Quote
Old 07/01/2019, 06:55 PM   #3
enzulikeS
Big Clucker
 
Join Date: Jan 2018
Posts: 156
Reputation: 0
Default Re: why doesnt update in database

Quote:
Originally Posted by Y_Less View Post
There's no `WHERE`.
i don t get it what to do :<
enzulikeS is offline   Reply With Quote
Old 07/01/2019, 07:12 PM   #4
Eoussama
High-roller
 
Eoussama's Avatar
 
Join Date: Jul 2016
Location: Kingdom of Morocco // Tangier
Posts: 1,294
Reputation: 266
Default Re: why doesnt update in database

Simply add a “WHERE” clause for the query to work properly.

PHP Code:
UPDATE giftboxd SET `GiftBoxMoney`='%s' WHERE {something} = {something
Note that the “something” fields are for you to figure out what goes in their place.
__________________

|===[Web taxi]===|
List of my work
Github
Pastebin

|===[Interesting topics]===|
Semantic Versioning
Eoussama is online now   Reply With Quote
Old 08/01/2019, 03:48 PM   #5
enzulikeS
Big Clucker
 
Join Date: Jan 2018
Posts: 156
Reputation: 0
Default Re: why doesnt update in database

added WHERE `ID` but still nope..
enzulikeS is offline   Reply With Quote
Old 08/01/2019, 04:35 PM   #6
Y_Less
Beta Tester
 
Y_Less's Avatar
 
Join Date: Jun 2008
Location: 629 - git.io/Y
Posts: 15,461
Reputation: 3206
Default Re: why doesnt update in database

You need to actually give an ID. Show us the complete code as it is now.
Y_Less is offline   Reply With Quote
Old 09/01/2019, 08:22 PM   #7
enzulikeS
Big Clucker
 
Join Date: Jan 2018
Posts: 156
Reputation: 0
Default Re: why doesnt update in database

Code:
mysql_format(SQL,zzString,sizeof(zzString),"UPDATE `giftboxd` SET `GiftBoxMoney`='%s' WHERE `GiftBoxOn`='1'", GiftBoxInfo[playerid][pGiftBoxMoney], GiftBoxInfo[playerid][pGiftBoxOn]);
				mysql_tquery(SQL,zzString,"","");
enzulikeS is offline   Reply With Quote
Old 11/01/2019, 09:38 PM   #8
enzulikeS
Big Clucker
 
Join Date: Jan 2018
Posts: 156
Reputation: 0
Default Re: why doesnt update in database

anyone please?
enzulikeS is offline   Reply With Quote
Old 11/01/2019, 09:41 PM   #9
userid
Little Clucker
 
Join Date: Aug 2018
Location: Where you live
Posts: 32
Reputation: 4
Default Re: why doesnt update in database

Maybe you should start learning sql
userid is offline   Reply With Quote
Old 11/01/2019, 11:51 PM   #10
ConnorW
Big Clucker
 
ConnorW's Avatar
 
Join Date: Apr 2012
Location: Los Santos
Posts: 124
Reputation: 48
Default Re: why doesnt update in database

Post the giftbox enum, there should be a ID included. If so you can do it:

pawn Code:
mysql_format(SQL,zzString,sizeof(zzString),"UPDATE `giftboxd` SET `GiftBoxMoney`= '%s' WHERE `ID`= %i", GiftBoxInfo[playerid][pGiftBoxMoney], GiftBoxInfo[playerid][ID]);
    mysql_tquery(SQL,zzString);
Or else making sure it works:
pawn Code:
mysql_format(SQL,zzString,sizeof(zzString),"UPDATE `giftboxd` SET `GiftBoxMoney`= '%s' WHERE `ID`= %i", GiftBoxInfo[playerid][pGiftBoxMoney], GiftBoxInfo[playerid][ID]);
    mysql_tquery(SQL,zzString, "OnUpdateGiftBox", "i", GiftboxInfo[playerid][ID]);

    forward OnUpdateGiftBox(giftboxid);
    public OnUpdateGiftBox(giftboxid)
    {
        if(cache_affected_rows() > 0)
        {
            printf("Saved giftbox id %d", giftboxid);
        }
        else
        {
            printf("An error has occured while saving the giftbox");
        }
        return 1;
    }
But I'm sure you've done the giftbox defines wrong, this one looks weird
pawn Code:
if(IsPlayerInRangeOfPoint(playerid, 5.0, GiftBoxInfo[playerid][pGiftBoxPosX], GiftBoxInfo[playerid][pGiftBoxPosY], GiftBoxInfo[playerid][pGiftBoxPosZ]))

pawn Code:
for(new i = 0; i < MAX_PLAYERS; i++) //you could've done a MAX_GIFTBOX
{
    if(IsPlayerInRangeOfPoint(playerid, 5.0, GiftBoxInfo[i][pGiftBoxPosX], GiftBoxInfo[i][pGiftBoxPosY], GiftBoxInfo[i][pGiftBoxPosZ]))
    {
        //rest of your code
    }
}
Please search before posting and read this https://wiki.sa-mp.com/wiki/MySQL/R33 and this https://www.guru99.com/delete-and-update.html
__________________
ConnorW 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
TextLable doesnt update? MayaEU Scripting Help 17 27/06/2016 03:44 PM
Table doesnt appear when click on Database Aa12 Scripting Help 3 23/01/2016 02:24 PM
SQLite database no update adri1 Scripting Help 4 01/11/2013 03:26 AM
Mysql query succeeded but doesnt get in database! HELP! thimo Scripting Help 0 26/02/2012 08:51 AM
Mysql doesnt update into database andruz99 Help Archive 5 08/07/2011 01:21 PM


All times are GMT. The time now is 03:28 PM.


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