MySQL refuses to save users data
#1

Hello, I am trying to convert my script in to mysql. But it refuses to save users.
This is my register dialog:

pawn Код:
new EscapedText[60],Query[80];
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        mysql_real_escape_string(inputtext, EscapedText);
        format(Query,sizeof(Query),"INSERT INTO `users` (Username,Password,Score,AdminLevel) VALUES ('%s','%s,'1'0')",GetPName(playerid),EscapedText);
        mysql_query(Query);
        mysql_store_result();
        mysql_free_result();
        PlayerInfo[playerid][pSurvivors] = 1;
        IsInTut[playerid] = 1;
Using the mysql plugin by Stricken. Why dont the users save? :P
Reply
#2

You're inserting not updating
Reply
#3

I did a

pawn Код:
stock SaveStats(playerid)
{
    new Query[128];
    format(Query,sizeof(Query),"UPDATE `users` SET `Score` = '%i', `AdminLevel` = '%i' WHERE `Username` = '%s'",
    GetPlayerScore(playerid),
    GetPName(playerid));
    mysql_query(Query);
    mysql_free_result();
    return 1;
}
And put it in to when a player finishes the tutorial.
Still dosent save.

Sorry for being such a noob but im new to mysql
Reply
#4

Try ths:
pawn Код:
new EscapedText[60],Query[80];
        new name[MAX_PLAYER_NAME];
        GetPlayerName(playerid, name, sizeof(name));
        mysql_real_escape_string(inputtext, EscapedText);
        format(Query,sizeof(Query),"INSERT INTO `users` (Username,Password,Score,AdminLevel) VALUES ('%s','%s','1','0')",GetPName(playerid),EscapedText);
        mysql_query(Query);
        mysql_store_result();
        mysql_free_result();
        PlayerInfo[playerid][pSurvivors] = 1;
        IsInTut[playerid] = 1;
And this one
pawn Код:
stock SaveStats(playerid)
{
    new Query[128];
    format(Query,sizeof(Query),"UPDATE `users` SET `Score` = '%i', `AdminLevel` = '%i' WHERE `Username` = '%s'",
    GetPlayerScore(playerid),
    //what about the AdminLevel ?
    PInfo[playerid][pAdminLevel],//change with your defines
    GetPName(playerid));
    mysql_query(Query);
    mysql_free_result();
    return 1;
}
Reply
#5

No still dosent work
Reply
#6

Try these
pawn Код:
stock SaveStats(playerid)
{
    new Query[128];
    format(Query,sizeof(Query),"UPDATE `users` SET `Score`= %i, /*`AdminLevel`= %i*/ WHERE `Username` = '%s'", GetPlayerScore(playerid), GetPName(playerid));
    mysql_query(Query);
    return 1;
}
First of all you don't need a '(Apostrophe) on an Integer you only need '(Apostrophe) on a string, and second you don't free the result when you're updating it, you only free the result when loading the Player's information, I hope this works!

PS: You forgot to put your Admin level Variable, just remove the /* */ when you added the AdminLevel variable
Reply
#7

Quote:
Originally Posted by pds2012
Посмотреть сообщение
Try these
pawn Код:
stock SaveStats(playerid)
{
    new Query[128];
    format(Query,sizeof(Query),"UPDATE `users` SET `Score`= %i, /*`AdminLevel`= %i*/ WHERE `Username` = '%s'", GetPlayerScore(playerid), GetPName(playerid));
    mysql_query(Query);
    return 1;
}
First of all you don't need a '(Apostrophe) on an Integer you only need '(Apostrophe) on a string, and second you don't free the result when you're updating it, you only free the result when loading the Player's information, I hope this works!

PS: You forgot to put your Admin level Variable, just remove the /* */ when you added the AdminLevel variable
What about the AdminLevel ?
Reply
#8

Enable the mysql_logs, and give us a log.
Reply
#9

Quote:
Originally Posted by x96664
Посмотреть сообщение
What about the AdminLevel ?
He forgot to put the AdminLevel variable, to be able to save the Player's admin level.

It should look like this
pawn Код:
//If uses Enum
pInfo[playerid][AdminLevel] or PlayerInfo[playerid][AdminLevel]
//or normal variable
AdminLevel[playerid]
If you forgot to add the variable while updating the Player's information could result a Saving Problem
Reply
#10

Still dosent work.

And this is the mysql.log

Код:
[Sat Sep 28 22:23:08 2013] Connected (0) to samp01_db @ Localhost via UNIX socket.
[Sat Sep 28 22:23:08 2013] MySQL Server Version 5.5.32-cll.
[Sat Sep 28 22:23:25 2013] Error (0): Failed to exeute query. 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 ''Daryl_Raleigh' at line 1.
[Sat Sep 28 22:23:25 2013] Error (0): Function: mysql_store_result called when no prior successful query executed. 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 ''Daryl_Raleigh' at line 1.
[Sat Sep 28 22:24:24 2013] Error (0): Failed to exeute query. 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 ''Daryl_Raleigh' at line 1.
[Sat Sep 28 22:24:24 2013] Error (0): Function: mysql_store_result called when no prior successful query executed. 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 ''Daryl_Raleigh' at line 1.
Edit:

This all the lines that I have MySQL lines on:

pawn Код:
stock SaveStats(playerid)
{
    new Query[128];
    format(Query,sizeof(Query),"UPDATE `users` SET `Score`= %i, `AdminLevel`= %i WHERE `Username` = '%s'", GetPlayerScore(playerid),PlayerInfo[playerid][pAdmin], GetPName(playerid));
    mysql_query(Query);
    return 1;
}
stock LoginPlayer(playerid,const password[])
{
    new EscapedText[60], Query[80];
    new name[MAX_PLAYER_NAME];
    GetPlayerName(playerid, name, sizeof(name));
    mysql_real_escape_string(password, EscapedText);
    format(Query,sizeof(Query),"SELECT * FROM `users` WHERE `Username` = '%s' AND `Password` = '%s'",name,EscapedText);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        SendClientMessage(playerid,COLOR_RED,"You have been logged in!");
        LoadStats(playerid);
    }
    else
    {
        SendClientMessage(playerid,RED,"Wrong password!");
        Kick(playerid);
    }
    mysql_free_result();
    return 1;
}

if(strlen(inputtext) == 0)
        {
            ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "Welcome to Island Survival", "{FFFFFF}Welcome to {FF0000}Island Survival:RP\n{FFFFFF}You are about to make an account here!\n\n\n{00FF00}Type in your password you want!", "Register", "Leave");
        }
        else
        {
            LoginPlayer(playerid,inputtext);
        }

OnPlayerConnect

new Query[80],pNamE[24];
    GetPlayerName(playerid,pNamE,24);
    format(Query,sizeof(Query),"SELECT `Username` FROM `users` WHERE `Username` = '%s' LIMIT 1;",pNamE);
    mysql_query(Query);
    mysql_store_result();
    if(mysql_num_rows() != 0)
    {
        ShowPlayerDialog(playerid, LOGIN, DIALOG_STYLE_PASSWORD, "Welcome back!", "Welcome back to Island Survival!\n\nType in your password below to login", "Login", "Leave");
    }
    else
    {
        ShowPlayerDialog(playerid, REGISTER, DIALOG_STYLE_PASSWORD, "Welcome to Island Survival", "{FFFFFF}Welcome to {FF0000}Island Survival:RP\n{FFFFFF}You are about to make an account here!\n\n\n{00FF00}Type in your password you want!", "Register", "Leave");
    }
        mysql_free_result();

enum pInfo
{
    Username[23],
    Password[24],
    pAdmin,
    pHelper,
    pScore,
    pWaterBottle,
    pOthers,
    pFaction,
    pRank,
    pLeader,
    pSurvivors,
    pFishingNet,
    pBoar,
    pBoarMeat,
    pNote,
    pRope,
    pFruit,
    pFishingRod,
    pSkin,
    pMale,
    pFemale,
    pPlayTime,
    pWater,
    pFish,
    pHeroin,
    pMatches,
    pWood,
    pBerry,
    pWhiskey,
    pMask,
    pClothes,
    pFishDone,
    pMute,
    pRmute,
    pJailed,
    pJailTime,
    pRespect,
    pCoOwner,
    pHunter,
    pDrugAddict,
    pDoctor,
    pThief,
    pFisher,
    pTech,
    pGun,
    pAmmo,
    pAmmo2,
    pAmmo3,
    pAmmo4,
    pAmmo5,
    pGun2,
    pGun3,
    pGun4,
    pGun5,
    Float:pPos_x,
    Float:pPos_y,
    Float:pPos_z,
    pVip,
    pWalkieTalkie,
    pWalkieBroken,
    pChoosenTeam,
    pRelationShip,
    pRelationWith[125],
    pInt,
    pWarn,
    pSlots,
    pBackPack,
    pSlotsFree,
    pBan,
}
new PlayerInfo[MAX_PLAYERS][pInfo];
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)