AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Solved Database messing with me again. (https://forums.alliedmods.net/showthread.php?t=309714)

mug1wara 08-04-2018 19:27

Database messing with me again.
 
Wadup, getting this annoying ass error: Exception reported: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Something has got to be wrong with this, since the tables are being created but client is never inserted into the database.
PHP Code:

void SQL_LoadClient(int iClient)
{
    
GetClientAuthId(iClientAuthId_Steam2g_sSteamid[iClient], sizeof(g_sSteamid[]));
    
    
char sQuery[256];
    
Format(sQuerysizeof(sQuery), "SELECT * FROM mugistats WHERE steam_id = \"%s\""g_sSteamid[iClient]);
    
    
g_hDatabase.Query(SQL_AuthorizationsQueryGetClientUserId(iClient));
}

public 
void SQL_Authorization(Database hDatabaseDBResultSet hResults, const char[] sErrorint iData)
{
    if (
hResults == null)
        
ThrowError(sError);
    
    
int iClient GetClientOfUserId(iData);
    
    if (
IsValidClient(iClient))
    {
        if (
hResults.RowCount != 0)
        {
            
hResults.FetchRow();
            
            
g_iExp[iClient] = hResults.FetchInt(2);
            
g_iKills[iClient] = hResults.FetchInt(3);
            
g_iDeaths[iClient] = hResults.FetchInt(4);
            
g_iHeadshots[iClient] = hResults.FetchInt(5);
            
g_iSuicides[iClient] = hResults.FetchInt(6);
            
g_iDamage[iClient] = hResults.FetchInt(7);
            
g_iKnifeKills[iClient] = hResults.FetchInt(8);
            
g_iNadeKills[iClient] = hResults.FetchInt(9);
            
g_iRoundsWon[iClient] = hResults.FetchInt(10);
            
g_iRoundsLost[iClient] = hResults.FetchInt(11);
            
g_iWallbangs[iClient] = hResults.FetchInt(12);
            
g_iAWPNoscopes[iClient] = hResults.FetchInt(13);
            
g_iSSG08Noscopes[iClient] = hResults.FetchInt(14);
            
g_iEntryKills[iClient] = hResults.FetchInt(15);
            
g_iEntryDeaths[iClient] = hResults.FetchInt(16);
        }
        
        else
        {
            
char sQuery[256];
            
Format(sQuerysizeof(sQuery), "INSERT INTO mugistats (steam_id, name, exp, kills, deaths, headshots, suicides, damage, knifekills, nadekills, rounds_won, rounds_lost, wallbangs, awp_noscopes, ssg08_noscopes, entry_kills, entry_deaths) VALUES (\"%s\", \"%N\", '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d', '%d')"g_sSteamid[iClient], iClientg_iExp[iClient], g_iKills[iClient], g_iDeaths[iClient], g_iHeadshots[iClient], g_iSuicides[iClient], g_iDamage[iClient], g_iKnifeKills[iClient], g_iNadeKills[iClient], g_iRoundsWon[iClient], g_iRoundsLost[iClient], g_iWallbangs[iClient], g_iAWPNoscopes[iClient], g_iSSG08Noscopes[iClient], g_iEntryKills[iClient], g_iEntryDeaths[iClient]);
            
            
g_hDatabase.Query(SQL_ErrorsQuery);
        }
    }



Neuro Toxin 08-04-2018 20:28

Re: Database messing with me again.
 
Print your query string to console and try it in something like myphpadmin.

Addicted. 08-05-2018 21:53

Re: Database messing with me again.
 
In addition you should also always check the return of GetClientAuthId

mug1wara 08-06-2018 09:39

Re: Database messing with me again.
 
That wasn't the case.

Second query, I use 256 buffer size when It's an easy 300+

Maxximou5 08-06-2018 15:28

Re: Database messing with me again.
 
Will come back to this. Found more issues.

Ilusion9 08-07-2018 09:19

Re: Database messing with me again.
 
You should use '%s' instead of \"%s\". And don't forget about database.Escape when you insert a name in your database (it can contains quotes or apostrophes)

mug1wara 08-07-2018 19:01

Re: Database messing with me again.
 
Quote:

Originally Posted by Ilusion9 (Post 2608885)
You should use '%s' instead of \"%s\". And don't forget about database.Escape when you insert a name in your database (it can contains quotes or apostrophes)

Since I used AuthId_Steam2 I decided to escape the quotes because the authtype contains semicolons which split the string.


All times are GMT -4. The time now is 23:57.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.