mySQL error
#1

I have this code to register a new user, it creates the table perfectly, but when it has to insert the values, it doesn't insert them. I don't know why.

Код:
mysql_query("CREATE TABLE IF NOT EXISTS Usuarios (Id_User INT(5) NOT NULL AUTO_INCREMENT, NombreRP VARCHAR(34) NOT NULL, Contraseсa VARCHAR(34) NOT NULL, PRIMARY KEY (Id_User))");
	mysql_query("ALTER TABLE Usuarios ADD Admin INT(5) NOT NULL");
	mysql_query("ALTER TABLE Usuarios ADD Cartera INT(5) NOT NULL");
	mysql_query("ALTER TABLE Usuarios ADD Edad INT(5) NOT NULL");
	mysql_query("ALTER TABLE Usuarios ADD Sexo INT(5) NOT NULL");
Код:
stock Register(playerid, password[])
{
	if(AccountExists[playerid])
		return SendClientMessage(playerid, COLOR_RED, "[Account] You're registered!");

 	if(PlayerLogged[playerid])
		return SendClientMessage(playerid, COLOR_RED, "[Account] You're logged in!");

	CheckMySQL();

	new Insertar[256];
	format(Insertar, 256, "INSERT INTO usuarios (NombreRP, Contraseсa, Admin, Cartera, Edad, Sexo) VALUES ('%s', '%s', '0', '0', '0', '0')", PlayerInfo[playerid][NombreRP], password);
	mysql_query(Insertar);

    AccountExists[playerid] = 1;
	SendClientMessage(playerid, COLOR_YELLOW, "[Account] Your account has been created!");

	return 1;
}
Reply
#2

I don't see the point of altering table to add more columns while you could have created them by the first query itself. Also give more details about your problem. Is there any error reporting on log?
Reply
#3

There is no error reporting on log, it doesn't create the User, it sends the 'Your account has been created' message but it doesn't create it...
Reply
#4

Код:

CheckMySQL();
mysql_query(Insertar);
https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_query
read the parameters
Reply
#5

I'm using MySQL R5 version, it doesn't need those parameters.
Reply
#6

Why? Because you like old shit? You must have a reason.
Reply
#7

Quote:
Originally Posted by Vince
Посмотреть сообщение
Why? Because you like old shit? You must have a reason.
There are some functions that in the newest versions aren't. Anyways, which version do you recommend me to use?
Reply
#8

Quote:
Originally Posted by Antenastyle
Посмотреть сообщение
There are some functions that in the newest versions aren't. Anyways, which version do you recommend me to use?
If they are under another name, it doesn't mean they don't exist. And that's a weird question, just get the latest (R42) and have a look at the R40 wiki page.
Reply
#9

Quote:
Originally Posted by Antenastyle
Посмотреть сообщение
There are some functions that in the newest versions aren't. Anyways, which version do you recommend me to use?
I promise you that whichever functions you're thinking of (do share) either still exist or have been purposefully replaced with a better version/method. The latest version is obviously recommended since it'll have the most recent features and have patches of bugs within older versions. The current method you're using is completely wrong, of course it sends the message regardless of the outcome of the query. You should use threaded queries, which will also help with debugging not to mention server performance. You're also exposing yourself to SQL injection by not escaping user strings. The mysql_format has an inline %e specifier to escape strings (as appose to using %s), along with the mysql_escape_string function.

Example:
pawn Код:
// in command
new local_query[100];
mysql_format(SQLHandle, local_query, sizeof local_query, "INSERT QUERY");
mysql_tquery(SQLHandle, local_query, "OnAccountCreated", "i", playerid);

forward OnAccountCreated(playerid);
public OnAccountCreated(playerid)
{
       if(cache_affected_rows() == 0)
             return SendClientMessage(playerid, -1, "Unable to create account.");
 
       new
             local_string[64];

       format(local_string, sizeof local_string, "Account created, row ID: %d.", cache_insert_id());
       SendClientMessage(playerid, -1, local_string);

       // do whatever else
       return 1;
}
You can find recent plugin releases here.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)