MYSQL INSERT INTO
#1

Okay, I made a registration system.
one part when he enters a password and it does this.

Код:
stock CreatePlayerAccount(playerid, password[])
{
	new escapename[MAX_PLAYER_NAME], query[256], IP[100];
	mysql_real_escape_string(GetName(playerid), escapename);
	GetPlayerIp(playerid, IP, sizeof(IP));
	format(query, sizeof(query), "INSERT INTO `users` (name, password, registered, cash, bank, level, exp, hours, admin, helper, playerIP) VALUES ('%s', '%s', 0, 5000, 10000, 1, 0, 0, 0, 0, '%s')",escapename,password,IP);
	mysql_function_query(dbHandle, query, true, "OnPlayerCreateAccount", "d", playerid);
	return 1;
}
then it moves to:
Код:
public OnPlayerCreateAccount(playerid)
{
	ShowDialog(playerid, Show:<Email>, DIALOG_STYLE_INPUT, ""EMBED_YELLOW"LS:RP Registration"EMBED_WHITE"", ""EMBED_WHITE"To be able to play you'll have to enter your EMAIL address, in case you will lose your password.\n("EMBED_BLUE"If you will enter an invalid adress you won't be able to get your password"EMBED_WHITE")", "Continue", "Quit");
	return 1;
}
Dialog response:

Код:
Dialog:Email(playerid, response, listitem, inputtext[])
{
	new str[256], escemail[100];
    if (response)
    {
		if(!strlen(inputtext)) 
		{
			ShowDialog(playerid, Show:<Email>, DIALOG_STYLE_INPUT, ""EMBED_YELLOW"LS:RP Registration"EMBED_WHITE"", ""EMBED_WHITE"To be able to play you'll have to enter your EMAIL address, in case you will lose your password.\n("EMBED_BLUE"If you will enter an invalid adress you won't be able to get your password"EMBED_WHITE")", "Continue", "Quit");
			return 1;
		}
		mysql_real_escape_string(inputtext, escemail);
		InsertPlayerEmail(playerid, escemail);
    }
    else
    {	
		
    }
	return 1;
}
And finally:
Код:
stock InsertPlayerEmail(playerid, email[])
{
	new query[256];
	format(query, sizeof(query), "INSERT INTO `users` (email) VALUES ('%s')", email);
	mysql_function_query(dbHandle, query, true, "", "");
	return 1;
}
first insert works good, but when it comes to email, it makes another line ...
like this:



I need help thanks.
Reply
#2

Well of course it inserts a new row if you tell it to insert a new row! Use the update statement for the e-mail. Also, to guarantee database integrity you should set the 'NOT NULL' option on fields that must not be left empty. Which is pretty much any field.
Reply
#3

i guess this will be good?

format(query, sizeof(query), "UPDATE `users` SET `email` = '%s' WHERE `name` = '%s'", email, GetName(playerid));
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)