MySQL - Problem with Saving into IDґs
#1

Hey guys,

Iґm still working on my Attack and Defend gamemode and actually I try to create a /build command for bases.
The Positions are getting printed in the debugmode but it just dont saves the values in the database.

I want it to add a new row with continueing IDґs
@Edit: Here is a Screenshot of the DB: http://www11.pic-upload.de/15.02.15/jdws6ld2syhj.png

Here is the code:

PHP код:
CMD:savebase(playeridparams[])
{
    if(
BuildMode[playerid] == 1)
    {
        if(
BuildProgress[playerid] == 6)
        {
             new 
string[128],query[1024];
            
            
mysql_format(mysqlquerysizeof(query), "INSERT INTO `bases` (`Name`, `Description`, `Creater`, `Interior`, `aPosX`, `aPosY`, `aPosZ`, `aFacingAng`, `dPosX`, `dPosY`, `dPosZ`, `dFacingAng`, `cpPosX`, `cpPosY`, `cpPosZ`) VALUES ('%s', '%s', '%s', '%d', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f')"BuildInfo[playerid][BaseName], BuildInfo[playerid][Description],PlayerName(playerid), BuildInfo[playerid][Interior],
            
BuildInfo[playerid][aPosX],BuildInfo[playerid][aPosY],BuildInfo[playerid][aPosZ],BuildInfo[playerid][aFacingAng],BuildInfo[playerid][dPosX],BuildInfo[playerid][dPosY],BuildInfo[playerid][dPosZ],BuildInfo[playerid][dFacingAng],
            
BuildInfo[playerid][cpPosX],BuildInfo[playerid][cpPosY],BuildInfo[playerid][cpPosZ]);
            
BuildInfo[playerid][ID] = cache_insert_id();
            
printf(query); //Debug
            
BuildProgress[playerid] = 0;
            
BuildMode[playerid] = 0;
            
SpawnPlayer(playerid);
            
            
format(stringsizeof string,"{4BFF5D}Your base have been saved! {FFFFFF}ID: %d",BuildInfo[playerid][ID]);
            
SendClientMessage(playerid,0x4BFF5DFF,string);
            
printf("%s created a new base - ID: %d",PlayerName(playerid), BuildInfo[playerid][ID]);
        }
        else return 
SendClientMessage(playerid,0xFFFFFFFF,"{FFFFFF}Error: {791A1A}You cant use this command yet!");
    }
    else  return 
SendClientMessage(playerid,0xFFFFFFFF,"{FFFFFF}Error: {791A1A}You are currently not in the Buildmode!");
    return 
1;

And here is the text out of the rcon console

Quote:

[16:16:51] INSERT INTO `bases` (`Name`, `Description`, `Creater`, `Interior`, `aPosX`, `aPosY`, `aPosZ`, `aFacingAng`, `dPosX`, `dPosY`, `dPosZ`, `dFacingAng`, `cpPosX`, `cpPosY`, `cpPosZ`) VALUES ('saize test wf lobby', 'so pro', '[PeM]Saize420', '18', '1728.435', '-1668.262', '22.609', '22.609', '1728.563', '-1668.736', '22.609', '22.609', '1726.611', '-1668.707', '22.58')
[16:16:51] [PeM]Saize420 created a new base - ID: 0

But it just doesnt saves it in the ID, I dont know what Iґm doing wrong
Reply
#2

mysql_format merely formats the query. You still need to send it with mysql_tquery. Then you also need to wait for the result to use cache_insert_id (means you need a callback).
Reply
#3

Quote:
Originally Posted by Vince
Посмотреть сообщение
mysql_format merely formats the query. You still need to send it with mysql_tquery. Then you also need to wait for the result to use cache_insert_id (means you need a callback).
Man dat Vince, you always help me when something is wrong with my MySQL

Well now it saves it in the DB but the first ID is 2 and I dont really know why фФ
+ It always prints 0 as the ID

Code:

PHP код:
public OnBaseCreate(playerid)
{
    new 
string[128];
    
BuildInfo[playerid][ID] = cache_get_field_content_int(0"ID");
     
BuildInfo[playerid][BaseName] = cache_get_field_content_int(0"BaseName");
      
BuildInfo[playerid][Description] = cache_get_field_content_int(0"Description");
       
BuildInfo[playerid][Creater] = cache_get_field_content_int(0"Creater");
    
BuildInfo[playerid][Interior] = cache_get_field_content_int(0"Interior");
    
BuildInfo[playerid][aPosX] = cache_get_field_content_float(0"aPosX");
    
BuildInfo[playerid][aPosY] = cache_get_field_content_float(0"aPosX");
     
BuildInfo[playerid][aPosZ] = cache_get_field_content_float(0"aPosX");
      
BuildInfo[playerid][aFacingAng] = cache_get_field_content_float(0"aFacingAng");
    
BuildInfo[playerid][dPosX] = cache_get_field_content_float(0"dPosX");
    
BuildInfo[playerid][dPosY] = cache_get_field_content_float(0"dPosY");
    
BuildInfo[playerid][dPosZ] = cache_get_field_content_float(0"dPosZ");
    
BuildInfo[playerid][dFacingAng] = cache_get_field_content_float(0"dFacingAng");
    
    
format(stringsizeof string,"{4BFF5D}Your base have been saved! {FFFFFF}ID: %d",BuildInfo[playerid][ID]);
    
SendClientMessage(playerid,0x4BFF5DFF,string);
     
printf("%s created a new base - ID: %d",PlayerName(playerid), BuildInfo[playerid][ID]);
    return 
1;

PHP код:
CMD:savebase(playeridparams[])
{
    if(
BuildMode[playerid] == 1)
    {
        if(
BuildProgress[playerid] == 6)
        {
             new 
query[1024];
            
            
mysql_format(mysqlquerysizeof(query), "INSERT INTO `bases` (`Name`, `Description`, `Creater`, `Interior`, `aPosX`, `aPosY`, `aPosZ`, `aFacingAng`, `dPosX`, `dPosY`, `dPosZ`, `dFacingAng`, `cpPosX`, `cpPosY`, `cpPosZ`) VALUES ('%s', '%s', '%s', '%d', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f')"BuildInfo[playerid][BaseName], BuildInfo[playerid][Description],PlayerName(playerid), BuildInfo[playerid][Interior],
            
BuildInfo[playerid][aPosX],BuildInfo[playerid][aPosY],BuildInfo[playerid][aPosZ],BuildInfo[playerid][aFacingAng],BuildInfo[playerid][dPosX],BuildInfo[playerid][dPosY],BuildInfo[playerid][dPosZ],BuildInfo[playerid][dFacingAng],
            
BuildInfo[playerid][cpPosX],BuildInfo[playerid][cpPosY],BuildInfo[playerid][cpPosZ]);
            
mysql_tquery(mysqlquery"OnBaseCreate""i"playerid);
            
printf(query); //Debug
            
BuildProgress[playerid] = 0;
            
BuildMode[playerid] = 0;
            
SpawnPlayer(playerid);
            
        }
        else return 
SendClientMessage(playerid,0xFFFFFFFF,"{FFFFFF}Error: {791A1A}You cant use this command yet!");
    }
    else  return 
SendClientMessage(playerid,0xFFFFFFFF,"{FFFFFF}Error: {791A1A}You are currently not in the Buildmode!");
    return 
1;

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)