[Mysql] Problem with a function -
anou1 - 19.07.2014
Hi everybody,
I'm doing a CMD to rename a connected player, but it's seems that the whole function don't execute, just a part of it.
It only go to printf "3" or "3-2".
Pastbin:
http://pastebin.com/wQmQQEeu
If you have any tips for me, for exemple to optimize it or something else, just tell me
Thank you (:
Re: [Mysql] Problem with a function -
sammp - 19.07.2014
UPDATE` cars `SET` Owner `= '% s' WHERE` ID `=%
Ok change that stuff to:
pawn Код:
UPDATE `cars` SET `Owner` = '%s' WHERE `ID` = '%d'
I suggest you learn MySQL as you did the whole thing wrong.
Re: [Mysql] Problem with a function -
anou1 - 19.07.2014
What the ... ?
Did you at least read the pastbin ?
Where did I done something like this ?
Re: [Mysql] Problem with a function -
sammp - 19.07.2014
I took it from this:
pawn Код:
public OnJoueurRenommer ( playerid, id, name )
{
printf ( "1" ) ;
new query [ 128 ] , name2 [ MAX_PLAYER_NAME ] ;
if ( cache_get_row_count ( ) ) return SendClientMessage ( playerid, Red, "This player is already in the database." ) ;
GetPlayerName ( playerid, joueuremetteur, sizeof ( joueuremetteur ) ) ;
GetPlayerName ( id, name2, sizeof ( name2 ) ) ;
printf ( "2" ) ;
new v1 = pInfo [ id ] [ ClefVoiture1 ] , v2 = pInfo [ id ] [ ClefVoiture2 ] , v3 = pInfo [ id ] [ ClefVoiture3 ] , v4 = pInfo [ id ] [ ClefVoiture4 ] ;
printf ( "3" ) ;
if ( pInfo [ id ] [ ClefVoiture1 ] ! = 1 )
{
size ( vInfo [ v1 ] [ vProprietaire ] , MAX_PLAYER_NAME, "% s" , joueurdestinataire ) ;
Format ( query, sizeof ( query ) , "UPDATE` cars `SET` Owner `= '% s' WHERE` ID `=% d" , joueurdestinataire, vInfo [ v1 ] [ vID ] ) ;
mysql_tquery ( mysql, query, "" , "" ) ;
}
printf ( "3-2" ) ;
if ( pInfo [ id ] [ ClefVoiture2 ] ! = 1 )
{
size ( vInfo [ v2 ] [ vProprietaire ] , MAX_PLAYER_NAME, "% s" , joueurdestinataire ) ;
Format ( query, sizeof ( query ) , "UPDATE` cars `SET` Owner `= '% s' WHERE` ID `=% d" , joueurdestinataire, vInfo [ v2 ] [ vID ] ) ;
mysql_tquery ( mysql, query, "" , "" ) ;
}
printf ( "3-3" ) ;
if ( pInfo [ id ] [ ClefVoiture3 ] ! = 1 )
{
size ( vInfo [ v3 ] [ vProprietaire ] , MAX_PLAYER_NAME, "% s" , joueurdestinataire ) ;
Format ( query, sizeof ( query ) , "UPDATE` cars `SET` Owner `= '% s' WHERE` ID `=% d" , joueurdestinataire, vInfo [ v3 ] [ vID ] ) ;
mysql_tquery ( mysql, query, "" , "" ) ;
}
printf ( "3-4" ) ;
if ( pInfo [ id ] [ ClefVoiture4 ] ! = 1 )
{
size ( vInfo [ v4 ] [ vProprietaire ] , MAX_PLAYER_NAME, "% s" , joueurdestinataire ) ;
Format ( query, sizeof ( query ) , "UPDATE` cars `SET` Owner `= '% s' WHERE` ID `=% d" , joueurdestinataire, vInfo [ v4 ] [ vID ] ) ;
mysql_tquery ( mysql, query, "" , "" ) ;
}
printf ( "4" ) ;
if ( pInfo [ id ] [ ClefMaison ] =! - 1 )
{
new m = pInfo [ id ] [ ClefMaison ] ;
size ( MINFO [ pInfo [ id ] [ ClefMaison ] ] [ mProprietaire ] , MAX_PLAYER_NAME, "% s" , joueurdestinataire ) ;
Format ( query, sizeof ( query ) , "UPDATE` houses `SET` Owner `= '% s' WHERE` ID `=% d" , joueurdestinataire, pInfo [ id ] [ ClefMaison ] ) ;
mysql_tquery ( mysql, query, "" , "" ) ;
ConfigurerMaison ( m, MINFO [ m ] [ mAchetee ] ) ;
}
if ( pInfo [ id ] [ ClefLocationMaison ] =! - 1 )
{
new m = pInfo [ id ] [ ClefLocationMaison ] ;
size ( MINFO [ pInfo [ id ] [ ClefLocationMaison ] ] [ mProprietaire ] , MAX_PLAYER_NAME, "% s" , joueurdestinataire ) ;
Format ( query, sizeof ( query ) , "UPDATE` houses `SET` Tenant `= '% s' WHERE` ID `=% d" , joueurdestinataire, pInfo [ id ] [ ClefLocationMaison ] ) ;
mysql_tquery ( mysql, query, "" , "" ) ;
ConfigurerMaison ( m, MINFO [ m ] [ mAchetee ] ) ;
}
printf ( "5" ) ;
Format ( query, sizeof ( query ) , "UPDATE` players `SET` username `= '% s' WHERE` ID `=% d" , joueurdestinataire, pInfo [ id ] [ ID ] ) ;
mysql_tquery ( mysql, query, "" , "" ) ;
printf ( "6" ) ;
Format ( query, sizeof ( query ) , "[ADMIN]:% s to rename% s to% s." , joueuremetteur, name2, joueurdestinataire ) ;
ChannelAdmin ( Red, query ) ;
printf ( "7" ) ;
Format ( query, sizeof ( query ) , "% s changed your name to% s." , joueuremetteur, joueurdestinataire ) ;
SendClientMessage ( id, LightBlue, query ) ;
printf ( "8" ) ;
SetPlayerName ( id, joueurdestinataire ) ;
printf ( "9" ) ;
return 1 ;
}
LEARN MYSQL. You're not doing it right.
Re: [Mysql] Problem with a function -
anou1 - 19.07.2014
I've never did this, I did this:
Your computer or your browser got a problem.
Код:
public OnJoueurRenommer(playerid, id, nom)
{
printf("1");
new query[128], nom2[MAX_PLAYER_NAME];
if(cache_get_row_count()) return SendClientMessage(playerid, Rouge, "Ce joueur existe dйjа dans la base de donnйe.");
GetPlayerName(playerid, joueuremetteur, sizeof(joueuremetteur));
GetPlayerName(id, nom2, sizeof(nom2));
printf("2");
new v1 = pInfo[id][ClefVoiture1], v2 = pInfo[id][ClefVoiture2], v3 = pInfo[id][ClefVoiture3], v4 = pInfo[id][ClefVoiture4];
printf("3");
if(pInfo[id][ClefVoiture1] != 1)
{
format(vInfo[v1][vProprietaire], MAX_PLAYER_NAME, "%s", joueurdestinataire);
format(query, sizeof(query), "UPDATE `voitures` SET `Proprietaire`='%s' WHERE `ID`=%d", joueurdestinataire, vInfo[v1][vID]);
mysql_tquery(mysql, query, "", "");
}
printf("3-2");
if(pInfo[id][ClefVoiture2] != 1)
{
format(vInfo[v2][vProprietaire], MAX_PLAYER_NAME, "%s", joueurdestinataire);
format(query, sizeof(query), "UPDATE `voitures` SET `Proprietaire`='%s' WHERE `ID`=%d", joueurdestinataire, vInfo[v2][vID]);
mysql_tquery(mysql, query, "", "");
}
printf("3-3");
if(pInfo[id][ClefVoiture3] != 1)
{
format(vInfo[v3][vProprietaire], MAX_PLAYER_NAME, "%s", joueurdestinataire);
format(query, sizeof(query), "UPDATE `voitures` SET `Proprietaire`='%s' WHERE `ID`=%d", joueurdestinataire, vInfo[v3][vID]);
mysql_tquery(mysql, query, "", "");
}
printf("3-4");
if(pInfo[id][ClefVoiture4] != 1)
{
format(vInfo[v4][vProprietaire], MAX_PLAYER_NAME, "%s", joueurdestinataire);
format(query, sizeof(query), "UPDATE `voitures` SET `Proprietaire`='%s' WHERE `ID`=%d", joueurdestinataire, vInfo[v4][vID]);
mysql_tquery(mysql, query, "", "");
}
printf("4");
if(pInfo[id][ClefMaison] != -1)
{
new m = pInfo[id][ClefMaison];
format(mInfo[pInfo[id][ClefMaison]][mProprietaire], MAX_PLAYER_NAME, "%s", joueurdestinataire);
format(query, sizeof(query), "UPDATE `maisons` SET `Proprietaire` ='%s' WHERE `ID`=%d", joueurdestinataire, pInfo[id][ClefMaison]);
mysql_tquery(mysql, query, "", "");
ConfigurerMaison(m, mInfo[m][mAchetee]);
}
if(pInfo[id][ClefLocationMaison] != -1)
{
new m = pInfo[id][ClefLocationMaison];
format(mInfo[pInfo[id][ClefLocationMaison]][mProprietaire], MAX_PLAYER_NAME, "%s", joueurdestinataire);
format(query, sizeof(query), "UPDATE `maisons` SET `Locataire`='%s' WHERE `ID`=%d", joueurdestinataire, pInfo[id][ClefLocationMaison]);
mysql_tquery(mysql, query, "", "");
ConfigurerMaison(m, mInfo[m][mAchetee]);
}
printf("5");
format(query, sizeof(query), "UPDATE `joueurs` SET `Username` ='%s' WHERE `ID`=%d", joueurdestinataire, pInfo[id][ID]);
mysql_tquery(mysql, query, "", "");
printf("6");
format(query, sizeof(query), "[ADMIN]:%s а changer le nom de %s en %s.", joueuremetteur, nom2, joueurdestinataire);
ChannelAdmin(Rouge, query);
printf("7");
format(query, sizeof(query), "%s a changй votre nom en %s.", joueuremetteur, joueurdestinataire);
SendClientMessage(id, BleuClair, query);
printf("8");
SetPlayerName(id, joueurdestinataire);
printf("9");
return 1;
}
Re: [Mysql] Problem with a function -
sammp - 19.07.2014
Must've been a Pastebin error.
Anyways I don't quite understand the problem.. Explain !
And i cant understand the code..
Edit > do mysql_log(LOG_ALL) and provide the logs
Re: [Mysql] Problem with a function -
anou1 - 19.07.2014
It's supposed to change the name of someone by an other name.
And if the guy we have to change the name, have vehicles or a house, it changes the name of the vehicle owner and house owner.
I don't know if I explained it good, but if you still don't understand tell me (:
Re: [Mysql] Problem with a function -
sammp - 19.07.2014
is joueurdestinataire defined locally or globally
Re: [Mysql] Problem with a function -
anou1 - 19.07.2014
"new joueurdestinataire[MAX_PLAYER_NAME];"
At the top of my script, I usually use it without any problem.
Re: [Mysql] Problem with a function -
sammp - 19.07.2014
Untested and im tired so it might not work
pawn Код:
CMD:changename(playerid, params[])
{
if(pInfo[playerid][Admin] >= 70)
{
new
query[128],
id,
nom[24];
if(sscanf(params, "us[24]", id, nom)) return SendClientMessage(playerid, Rouge: "Usage: /changename [playerid][new name]");
if(id == playerid) return SendClientMessage(playerid, Rouge, "Dont change your own name!");
if(id == INVALID_PLAYER_ID) return SendClientMessage(playerid, Rouge, "Playerid not connected!");
format(jouerdestinataire, sizeof(jouerdestinataire), "%s", nom);
mysql_format(mysql, query, sizeof(query), "SELECT * FROM `joueurs` WHERE `Username` = '%s' LIMIT 1", nom);
mysql_tquery(mysql, query, "OnJoueurRenommer", "dds", playerid, id, nom);
}
}
public OnJoueurRenommer(playerid, id, nom)
{
new
rows,
fields,
query[128];
cache_get_data(rows, fields, mysql);
if(rows)
{
SendClientMessage(playerid, Rouge, "Nom is already in use!");
}
else if(!rows)
{
new
v1 = pInfo[id][ClefVoiture1],
v2 = pInfo[id][ClefVoiture2],
v3 = pInfo[id][ClefVoiture3],
v4 = pInfo[id][ClefVoiture4];
if(v1 != 1)
{
format(vInfo[v1][vProprietaire], 24, "%s", joueurdestinataire);
mysql_format(mysql, query, sizeof(query), "UPDATE `voitures` SET `Proprietaire` = '%s' WHERE `ID` = '%d'", joueurdestinataire, vInfo[v1]);
mysql_query(mysql, query, sizeof(query), "", "");
}
}
}
Cannot be bothered finishing it, you get the drill with it though