SQL update not working
#1

hello and this is my code :

Код:
if(dialogid == SEXMENU)
	{
		if(response)
				{
         	        
             		
             		//man
        		    new name[MAX_PLAYER_NAME],query[128],psex[2];
					GetPlayerName(playerid,name,sizeof(name));
 		  			format(query,sizeof(query),"INSERT INTO accounts WHERE name='%s' (psex) VALUES ('1') ",psex);
					mysql_function_query(sqlconnect,query,false,"","");
   		    	    
   		    	    
   		    	    
   		    	    SetPlayerSkin(playerid, 185);
   		    	   	ShowPlayerDialog(playerid, AGEMENU, DIALOG_STYLE_INPUT, "{00C0FF}Amzius", "{FFFFFF}Kiek jums metu ?", "Submit", "Cancel");
 			        return 0;
 			    }
   				else
 	    		{
                   //woman
              	
        		      new name[MAX_PLAYER_NAME],query[128],psex[2];
					GetPlayerName(playerid,name,sizeof(name));
 		  			format(query,sizeof(query),"INSERT INTO accounts WHERE name='%s' (psex) VALUES ('2') ",psex);
					mysql_function_query(sqlconnect,query,false,"","");
   		    	    
   		    	    SetPlayerSkin(playerid, 193);
              		ShowPlayerDialog(playerid, AGEMENU, DIALOG_STYLE_INPUT, "{00C0FF}Amzius", "{FFFFFF}Kiek jums metu ?", "Submit", "Cancel");
 			        return 0;
				}
  	}
what do i want to do is update one column in my sql db this code dont give my any error but it wont update my sql aswell ware can by a problem .this code is about gender its gives dialog and let u choose what gender is yours and i need to save and set 1 for male and 2 for female into db , please help
Reply
#2

To start off if you're trying to update something in MySQL (SQL) then you DO NOT use 'INSERT' you use 'UPDATE', i suggest you do a little bit of the '******' searching, it'll help you figure your problem out.

Note: Make sure you insert the data into the database before you update otherwise there won't be anything to UPDATE, if you're trying to INSERT this data into the database as a 'Fresh' row then i suggest you do it when the register and update the needed and inputted information after.
Reply
#3

Update, not insert. And while we're at it, this block of code can be compacted. Always avoid duplicate code. If a change is to be made, you want to do it in only one place.

pawn Код:
if(dialogid == SEXMENU) // could probably use a switch here, as well
{
    new name[MAX_PLAYER_NAME], query[128];
    GetPlayerName(playerid, name, sizeof(name));
   
    format(query, sizeof(query), "UPDATE accounts SET psex=%d WHERE name='%s'", (response) ? 1 : 2, name);
    mysql_function_query(sqlconnect, query, false, "", "");
   
    SetPlayerSkin(playerid, (response) ? 185 : 193);
    ShowPlayerDialog(playerid, AGEMENU, DIALOG_STYLE_INPUT, "{00C0FF}Amzius", "{FFFFFF}Kiek jums metu ?", "Submit", "Cancel");
}
Reply
#4

Quote:
Originally Posted by Vince
Посмотреть сообщение
Update, not insert. And while we're at it, this block of code can be compacted. Always avoid duplicate code. If a change is to be made, you want to do it in only one place.

pawn Код:
if(dialogid == SEXMENU) // could probably use a switch here, as well
{
    new name[MAX_PLAYER_NAME], query[128];
    GetPlayerName(playerid, name, sizeof(name));
   
    format(query, sizeof(query), "UPDATE accounts SET psex=%d WHERE name='%s'", (response) ? 1 : 2, name);
    mysql_function_query(sqlconnect, query, false, "", "");
   
    SetPlayerSkin(playerid, (response) ? 185 : 193);
    ShowPlayerDialog(playerid, AGEMENU, DIALOG_STYLE_INPUT, "{00C0FF}Amzius", "{FFFFFF}Kiek jums metu ?", "Submit", "Cancel");
}
i did like this
Код:
format(query,sizeof(query),"UPDATE accounts SET psex='1' WHERE name='%s' ",psex);
but its still not working and i sow example of your and have few questions %d is meens selection right ?

i tierd your way and its works perfectly tnx
Reply
#5

could you help my with this one aswell


Код:
//sql
        new name[MAX_PLAYER_NAME],query[128],page[10];
		GetPlayerName(playerid,name,sizeof(name));
        new input = mysql_escape_string(inputtext,page,sqlconnect);
		format(query,sizeof(query),"UPDATE accounts SET page=input WHERE name='%s' ",name,page);
		mysql_function_query(sqlconnect,query,false,"","");


		//--------
hare is age update i cant get my db updated as well its works with insert command , this is probably about page= cuz it cant get text that i input in dialog
Reply
#6

can some 1 help ? to update my sql with textinput ?

Код:
if(dialogid == AGEMENU)
	{
		if(response)
		{
  		
  		if(strlen(inputtext)>=2)
  		{
		//format(query, sizeof(query), "UPDATE accounts SET psex=%d WHERE name='%s'", (response) ? 1 : 2, name);
		//sql
        new name[MAX_PLAYER_NAME],query[128],page[10];
		GetPlayerName(playerid,name,sizeof(name));
  		new input = mysql_escape_string(inputtext,page,sqlconnect);
		format(query,sizeof(query),"UPDATE accounts SET page='input' WHERE name='%s' ",name,page);
		mysql_function_query(sqlconnect,query,false,"","");


		//--------

		ShowPlayerDialog(playerid, EMAILMENU, DIALOG_STYLE_INPUT, "{00C0FF}El.pasto adresas", "{FFFFFF}Iveskite savo el.pasto adresa ?\n\n{FFF1AF}El.pasto adresas bus reikalingas jeigu pamirsite slaptazodi", "Submit", "Cancel");

		}
		else
		{
		SendClientMessage(playerid,COLOR_RED,"Neivedete amziaus arba jusu amzius nera tinkamas ");
		ShowPlayerDialog(playerid, AGEMENU, DIALOG_STYLE_INPUT, "{00C0FF}Amzius", "{FFFFFF}Kiek jums metu ?", "Submit", "Cancel");
		}
		return 1;
		}
	}
Reply
#7

i manage to get sql updated with this code but i have wrong values if i put 22 on dialog i got 50 on sql if i put 99 on dialog sql update to 57

Код:
if(dialogid == AGEMENU)
	{
		if(response)
		{
  		
  		if(strlen(inputtext)>=2)
  		{
		
		//sql
        new name[MAX_PLAYER_NAME],query[128];
		GetPlayerName(playerid,name,sizeof(name));
		format(query,sizeof(query),"UPDATE accounts SET page = '%d' WHERE name='%s'", inputtext,name);
		mysql_function_query(sqlconnect,query,false,"","");

        

		

		//--------

		ShowPlayerDialog(playerid, EMAILMENU, DIALOG_STYLE_INPUT, "{00C0FF}El.pasto adresas", "{FFFFFF}Iveskite savo el.pasto adresa ?\n\n{FFF1AF}El.pasto adresas bus reikalingas jeigu pamirsite slaptazodi", "Submit", "Cancel");

		}
		else
		{
		SendClientMessage(playerid,COLOR_RED,"Neivedete amziaus arba jusu amzius nera tinkamas ");
		ShowPlayerDialog(playerid, AGEMENU, DIALOG_STYLE_INPUT, "{00C0FF}Amzius", "{FFFFFF}Kiek jums metu ?", "Submit", "Cancel");
		}
		return 1;
		}
Reply


Forum Jump:


Users browsing this thread: