Raised This Month: $ Target: $400
 0% 

Problem..


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ProIcons
Senior Member
Join Date: Jan 2009
Location: Greece - Salonica
Old 07-19-2009 , 05:25   Problem..
Reply With Quote #1

Well this code is not working properly, It INSERT into the db the same nick every time. I want to check if there is entry on players with username=Killer and if not to Insert else Update the entry.. can anyone help me?
PHP Code:
public hook_death()
{
   new 
game[3]
   
get_cvar_string("Game",game,2);
   if (
equal(game,"1"))
   {
      
      new 
Handle:result
      
new Killer[32],Victim[32]
      new 
Killernum read_data(1)
      new 
Victimnum read_data(2)
      new 
weapon get_user_weapon(Killernum); 
      new 
weapon2[30]
      
get_weaponname(weapon,weapon2,29)
      
replace_all(weapon230"weapon_""");
      
get_user_name(Killernum,Killer,31);
      
get_user_name(Victimnum,Victim,31);
      
server_print("%s Killed by %s with weapon %d (%s)",Victim,Killer,weapon,weapon2);
      
//result = SQL_PrepareQuery(con2,"SELECT * FROM `kills` where username=%s",Killer)
      //log_amx("%s",result);
      /*if (result == Empty_Handle)
      {
         server_print("Mpa O %s den eixe entry gia Guns, kai gia auto tha tou kataxorisw logika mia entry",Killer)
         result = SQL_PrepareQuery(con2, "INSERT INTO `kills` (`id`, `username`, `ak47`, `aug`, `awp`, `famas`, `g3sg1`, `galil`, `deagle`, `p90`, `p228`, `usp`, `mac10`, `mp5navy`, `scout`, `sg550`, `tmp`, `glock18`, `fiveseven`, `ump45`, `xm1014`, `m3`, `m4a1`, `m249`, `knife`, `elite`, `hegrenade`) VALUES (NULL, '%s', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)",Killer)
         SQL_Execute(result)
         result = SQL_PrepareQuery(con2, "UPDATE `kills` SET %s=%s+1 WHERE username='%s'",weapon2,weapon2,Killer)
         SQL_Execute(result)
      }
      else if (result != Empty_Handle)
      {
         result = SQL_PrepareQuery(con2, "UPDATE `kills` SET %s=%s+1 WHERE username='%s'",weapon2,weapon2,Killer)
         SQL_Execute(result)
      }
      SQL_FreeHandle(result)
      result = SQL_PrepareQuery(con2,"SELECT * FROM `deaths` where username=%s",Victim)
      if (result == Empty_Handle)
      {
         result = SQL_PrepareQuery(con2, "INSERT INTO `deaths` (`id`, `username`, `ak47`, `aug`, `awp`, `famas`, `g3sg1`, `galil`, `deagle`, `p90`, `p228`, `usp`, `mac10`, `mp5navy`, `scout`, `sg550`, `tmp`, `glock18`, `fiveseven`, `ump45`, `xm1014`, `m3`, `m4a1`, `m249`, `knife`, `elite`, `hegrenade`) VALUES (NULL, '%s', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)",Victim)
         SQL_Execute(result)
         result = SQL_PrepareQuery(con2, "UPDATE `deaths` SET %s=%s+1 WHERE username='%s'",weapon2,weapon2,Victim)
         SQL_Execute(result)
      }
      else if (result != Empty_Handle)
      {
         result = SQL_PrepareQuery(con2, "UPDATE `deaths` SET %s=%s+1 WHERE username='%s'",weapon2,weapon2,Victim)
         SQL_Execute(result)
      }
      SQL_FreeHandle(result)
      *///Killer DB
      
result SQL_PrepareQuery(con2,"SELECT * FROM players where username=%s",Killer)
      if(!
SQL_MoreResults(result))
      {
         
result SQL_PrepareQuery(con2"INSERT INTO `players` (id,username,kills,deaths,loses,wins,draws,banned,started,played,status) values(NULL,'%s','1','0','0','0','0','0','0','1','User')"Killer)
         
SQL_Execute(result)
      }
      else 
      {
         
result SQL_PrepareQuery(con2"UPDATE `players` SET kills=kills+1 WHERE username='%s'",Killer)
         
SQL_Execute(result)
      }
      
//Victim DB
      
result SQL_PrepareQuery(con2,"SELECT * FROM `players` where username=%s",Victim)
      if(!
SQL_MoreResults(result))
      {
         
result SQL_PrepareQuery(con2"INSERT INTO `players` (id,username,kills,deaths,loses,wins,draws,banned,started,played,status) values(NULL,'%s','0','1','0','0','0','0','0','1','User')"Victim)
         
SQL_Execute(result)
      }
      else
      {
         
result SQL_PrepareQuery(con2"UPDATE `players` SET deaths=deaths+1 WHERE username='%s'",Victim)
         
SQL_Execute(result)
      }
      
SQL_FreeHandle(result)
      return 
PLUGIN_CONTINUE
   
}
   return 
PLUGIN_CONTINUE

__________________
function rb return $regsubex($$1-,/(.)/g,$+($chr(2) $+ $chr(3),$r(2,15),$chr(2),\1))
ProIcons is offline
TheRadiance
Senior Member
Join Date: Nov 2007
Location: Kazakhstan
Old 07-19-2009 , 05:54   Re: Problem..
Reply With Quote #2

example:

PHP Code:
// ...;
#include <amxmodx>
#include <sqlx>
// ...;
new Handle:g_sql;

// ...;

new nick[32];
new 
result[32];
get_user_name(idnicksizeof (nick));
new 
Handle:query SQL_PrepareQuery(g_sql"SELECT `password` FROM `admins` WHERE `auth` = '%s'"nick);

SQL_Execute(query);

if (
SQL_MoreResults(query))
{
    
SQL_ReadResult(query0resultsizeof (result));
    
SQL_FreeHandle(query);
}

if (
strlen(result))
{
    
// result has been found in db;
}
else
{
    
// result hasn't been found in db;

TheRadiance is offline
Send a message via ICQ to TheRadiance
ProIcons
Senior Member
Join Date: Jan 2009
Location: Greece - Salonica
Old 07-19-2009 , 06:14   Re: Problem..
Reply With Quote #3

PHP Code:
new result[32];
      
query SQL_PrepareQuery(con2,"SELECT * FROM `players` where `username` = `%s`",Killer);
      
SQL_Execute(query); 
      if (
SQL_MoreResults(query))
      {
         
SQL_ReadResult(query0resultsizeof (result));
      } 
      if (
strlen(result))
      { 
         
query SQL_PrepareQuery(con2"UPDATE `players` SET kills=kills+1 WHERE username='%s'",Killer)
         
SQL_Execute(query)
      }
      else
      {
         
query SQL_PrepareQuery(con2"INSERT INTO `players` (id,username,kills,deaths,loses,wins,draws,banned,started,played,status) values(NULL,'%s','1','0','0','0','0','0','0','1','User')"Killer)
         
SQL_Execute(query)
      } 
Again, It is Only Insert to the db new entries
__________________
function rb return $regsubex($$1-,/(.)/g,$+($chr(2) $+ $chr(3),$r(2,15),$chr(2),\1))
ProIcons is offline
ProIcons
Senior Member
Join Date: Jan 2009
Location: Greece - Salonica
Old 07-19-2009 , 10:28   Re: Problem..
Reply With Quote #4

well is there something that check this thing?
__________________
function rb return $regsubex($$1-,/(.)/g,$+($chr(2) $+ $chr(3),$r(2,15),$chr(2),\1))
ProIcons is offline
ProIcons
Senior Member
Join Date: Jan 2009
Location: Greece - Salonica
Old 07-19-2009 , 18:15   Re: Problem..
Reply With Quote #5


query
= SQL_PrepareQuery(con2,"SELECT * FROM `players` where `username` = `%s`",Killer);


If username = %s to update and if not insert
__________________
function rb return $regsubex($$1-,/(.)/g,$+($chr(2) $+ $chr(3),$r(2,15),$chr(2),\1))
ProIcons is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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