SA-MP Forums Archive
SQL Problem. - 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: SQL Problem. (/showthread.php?tid=647783)



SQL Problem. - AlexMSK - 11.01.2018

PHP код:
CMD:notice(playeridparams[])
{
    if(
isnull(params))
    {
        return 
SendClientMessage(playeridCOLOR_GREY"/notice [text]")
    }
    if(
pInfo[playerid][pNotice] == 1)
    {
        return 
SendClientMessage(playeridCOLOR_GREY"You've used your notice. Type /deletenotice to delete it.")
    }
    else
    {
        
pInfo[playerid][pNotice] = 1;
        new 
string[127];
        
format(stringsizeof(string), "You've set your notice to %s"params)
        
SendClientMessage(playeridCOLOR_WHITEstring)
        
mysql_format(db_infoquerysizeof(query), "UPDATE players SET noticetext = %s WHERE pid = %i"paramsGetPlayerDBId(playerid)); 
        
mysql_tquery(db_infoquery"""");
    }
return 
1;

Now if i try it in game it says
PHP код:
DescriptionUnknown column 'Test' in 'field list' (index 0). Query// TEST is the params the player putted at /notice
[22:58:47UPDATE players SET noticetext Test WHERE pid 
What's the problem :/?


Re: SQL Problem. - Sew_Sumi - 11.01.2018

Well, it says the error. You may have used the output you got from /notice incorrectly (if you have just made this command and DB entry)

I'd suggest trying to re-import the sql if you are on a test box, but if this is a live server be very careful and simply make the field that it's missing.


When did it start happening, and what were you doing when it started.


Re: SQL Problem. - X337 - 11.01.2018

Код:
mysql_format(db_info, query, sizeof(query), "UPDATE players SET noticetext = '%e' WHERE pid = %i", params, GetPlayerDBId(playerid));
you have to enclose string with ' or "
and also, use %e instead of %s if the string can be inputted by player to escape string


Re: SQL Problem. - AlexMSK - 11.01.2018

Код:
UPDATE players SET noticetext = %s WHERE pid = %i
I simply tested the command in game, so i did /notice test and it gave me that error, the field exists in table structure, i dont know whats wrong with it..


Re: SQL Problem. - AlexMSK - 11.01.2018

Quote:
Originally Posted by X337
Посмотреть сообщение
Код:
mysql_format(db_info, query, sizeof(query), "UPDATE players SET noticetext = '%e' WHERE pid = %i", params, GetPlayerDBId(playerid));
you have to enclose string with ' or "
and also, use %e instead of %s if the string can be inputted by player to escape string
Worked, thanks a lot. I thought about this but never tested, much appreciated.