[Ajuda] mysql nгo salvando o que era pra salvar
#1

Bom criei sistema simples para salvar email caso precise de recuperar a senha porem nгo estб salvando valor fica em branco.

Код:
	case dREGISTER:
	{
		if(!response) { SendClientMessage(playerid, 1, ""rRED"SERVER: Vocк foi expulso automaticamente."); return Kick(playerid); }
		else
		{
			if(strlen(inputtext) < 1 || strlen(inputtext) > 20) { ShowPlayerDialog(playerid, dREGISTER, DIALOG_STYLE_INPUT, ""rBLUE"REGISTRO", ""rWRITE"Bem Vindo ao \nVocк pode "rRED"registrar"rWRITE" uma conta, digitando uma senha desejada aqui:", ""rWRITE"Registrar", ""rWRITE"Sair"); }
			else
			{
				new query[200];
    			format(query, sizeof(query), "INSERT INTO `users` (`username`, `userpass`, `usermail`, `score`, `money`) VALUES ('%s', '%s', '0', '0', '0')", ReturnName(playerid), inputtext);
    			mysql_function_query(MysqlConnect, query, true, "OnPlayerInterMail", "ds", playerid);
			}
		}
	}
		
function OnPlayerInterMail(playerid)
{
	ShowPlayerDialog(playerid, dMAIL, DIALOG_STYLE_INPUT, ""rBLUE"E-MAIL", ""rWRITE"Inisira um e-mail vбlido, para o caso de precisar recuperar sua senha!", ""rWRITE"Inserir", ""rWRITE"Sair");
	return 1;
}

case dMAIL:
		{
		    if(response)
		    {
				if(strlen(inputtext) < 1 || strlen(inputtext) > 80) { ShowPlayerDialog(playerid, dMAIL, DIALOG_STYLE_INPUT, ""rBLUE"E-MAIL", ""rWRITE"Inisira um e-mail vбlido, para o caso de precisar recuperar sua senha!", ""rWRITE"Inserir", ""rWRITE"Sair"); }
				else
				{
					new query[200];
					format(query, sizeof(query), "UPDATE `users` SET usermail = %s WHERE `username` = '%s'", inputtext, ReturnName(playerid));
					mysql_function_query(MysqlConnect, query, true, "OnPlayerRegistered", "ds", playerid);
				}
			}
		}
Reply
#2

Esqueceu de colocar os '' entre usarmail, lб no final. SET 'usermail' = %s.
Ps.: coloque as aspas corretas, pq to no celular e nгo tem as aspas usadas em sql aqui.
Reply
#3

Provavel motivo que eu vi, me desculpe se eu estiver errado ^^
Esta parte do cуdigo, nгo estб dentro da callback OnDialogResponse estб?
PHP код:
function OnPlayerInterMail(playerid)
{
    
ShowPlayerDialog(playeriddMAILDIALOG_STYLE_INPUT""rBLUE"E-MAIL"""rWRITE"Inisira um e-mail vбlido, para o caso de precisar recuperar sua senha!"""rWRITE"Inserir"""rWRITE"Sair");
    return 
1;

Caso nгo esteja, mande o log do mysql pf
Agora aqui vai algumas dicas.
  • Adcione ; no fins de seus querys.
  • Use mysql_format com %e, ou format com %s. Para escapar as strings.
  • Economize queries, apesar de ser multi thread, elas gastam RAM, entгo salve alguns dados em cache antes, e apуs estar tudo completo os envie ao banco de dados juntos ^^
Reply
#4

Quote:

Provavel motivo que eu vi, me desculpe se eu estiver errado ^^
Esta parte do cуdigo, nгo estб dentro da callback OnDialogResponse estб?
Код:
function OnPlayerInterMail(playerid) 
{ 
    ShowPlayerDialog(playerid, dMAIL, DIALOG_STYLE_INPUT, ""rBLUE"E-MAIL", ""rWRITE"Inisira um e-mail vбlido, para o caso de precisar recuperar sua senha!", ""rWRITE"Inserir", ""rWRITE"Sair"); 
    return 1; 
}
Caso nгo esteja, mande o log do mysql pf
Agora aqui vai algumas dicas.
Adcione ; no fins de seus querys.
Use mysql_format com %e, ou format com %s. Para escapar as strings.
Economize queries, apesar de ser multi thread, elas gastam RAM, entгo salve alguns dados em cache antes, e apуs estar tudo completo os envie ao banco de dados juntos ^^

Isso й uma callback e nгo estб dentro da OnDialogResponse.

Quote:
Originally Posted by Galhardo
Посмотреть сообщение
Esqueceu de colocar os '' entre usarmail, lб no final. SET 'usermail' = %s.
Ps.: coloque as aspas corretas, pq to no celular e nгo tem as aspas usadas em sql aqui.
Coloquei e mesmo assim nгo funcionou.

#EDIT: Log

Код:
[10:43:40]  
[10:43:40]  ** MySQL Debugging enabled (10/27/15)
[10:43:40]  
[10:43:40] >> mysql_connect(localhost, root, sampserver, ******) on port 3306
[10:43:40] CMySQLHandler::CMySQLHandler() - constructor called.
[10:43:40] CMySQLHandler::CMySQLHandler() - Connecting to "localhost" | DB: "sampserver" | Username: "root"
[10:43:40] CMySQLHandler::Connect() - Connection was successful.
[10:43:40] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.
[10:43:40] >> mysql_ping( Connection handle: 1 )
[10:43:40] CMySQLHandler::Ping() - Connection is still alive.
[10:43:40] >> mysql_query_callback( Connection handle: 1 )
[10:43:40] Passing query CREATE TABLE IF NOT EXISTS `users` (`id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(24) NOT NULL, `userpass` varchar(20) NOT NULL, `usermail` varchar(81) NOT NULL, `score` int(11) NOT NULL, `money` int(11) NOT NULL, PRIMARY KEY (`id`) ) | 
[10:43:40] ProcessQueryThread() - Query was successful. (CREATE TABLE IF NOT EXISTS `users` (`id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(24) NOT NULL, `userpass` varchar(20) NOT NULL, `usermail` varchar(81) NOT NULL, `score` int(11) NOT NULL, `money` int(11) NOT NULL, PRIMARY KEY (`id`) ))
[10:43:40] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[10:44:03] >> mysql_query_callback( Connection handle: 1 )
[10:44:03] Passing query SELECT * FROM `users` WHERE `username` = 'Luca' LIMIT 1 | d
[10:44:03] ProcessQueryThread(OnCheckAccount) - Query was successful. (SELECT * FROM `users` WHERE `username` = 'Luca' LIMIT 1)
[10:44:03] ProcessQueryThread(OnCheckAccount) - Data caching enabled.
[10:44:03] CMySQLHandler::StoreResult() - Result was stored.
[10:44:03] CMySQLHandler::FreeResult() - Result was successfully free'd.
[10:44:03] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[10:44:03] OnCheckAccount(d) - Threaded function called.
[10:44:03] >> cache_get_data( Connection handle: 1 )
[10:44:03] ProcessTick() - The cache has been cleared.
[10:44:06] >> mysql_query_callback( Connection handle: 1 )
[10:44:06] Passing query INSERT INTO `users` (`username`, `userpass`, `usermail`, `score`, `money`) VALUES ('Luca', 'senha', '0', '0', '0') | ds
[10:44:06] ProcessQueryThread(OnPlayerInterMail) - Query was successful. (INSERT INTO `users` (`username`, `userpass`, `usermail`, `score`, `money`) VALUES ('Luca', 'senha', '0', '0', '0'))
[10:44:06] ProcessQueryThread(OnPlayerInterMail) - Data caching enabled.
[10:44:06] CMySQLHandler::StoreResult() - No data to store.
[10:44:06] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[10:44:06] OnPlayerInterMail(ds) - Threaded function called.
[10:44:06] ProcessTick() - The cache has been cleared.
[10:44:11] >> mysql_query_callback( Connection handle: 1 )
[10:44:11] Passing query UPDATE `users` SET 'usermail' = lucas@ig.com.br WHERE `username` = 'Luca' | ds
[10:44:11] CMySQLHandler::ProcessQueryThread() - Error will be triggered to OnQueryError()
Reply
#5

PHP код:
mysql_function_query(MysqlConnectquerytrue"OnPlayerRegistered""d"playerid
Estava passando uma string, agora que vim perceber.
Reply
#6

Erro de sintaxe, faltam aspas pro email na query.
Reply
#7

Quote:
Originally Posted by lucaskill66
Посмотреть сообщение
Isso й uma callback e nгo estб dentro da OnDialogResponse.



Coloquei e mesmo assim nгo funcionou.

#EDIT: Log

Код:
[10:43:40]  
[10:43:40]  ** MySQL Debugging enabled (10/27/15)
[10:43:40]  
[10:43:40] >> mysql_connect(localhost, root, sampserver, ******) on port 3306
[10:43:40] CMySQLHandler::CMySQLHandler() - constructor called.
[10:43:40] CMySQLHandler::CMySQLHandler() - Connecting to "localhost" | DB: "sampserver" | Username: "root"
[10:43:40] CMySQLHandler::Connect() - Connection was successful.
[10:43:40] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.
[10:43:40] >> mysql_ping( Connection handle: 1 )
[10:43:40] CMySQLHandler::Ping() - Connection is still alive.
[10:43:40] >> mysql_query_callback( Connection handle: 1 )
[10:43:40] Passing query CREATE TABLE IF NOT EXISTS `users` (`id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(24) NOT NULL, `userpass` varchar(20) NOT NULL, `usermail` varchar(81) NOT NULL, `score` int(11) NOT NULL, `money` int(11) NOT NULL, PRIMARY KEY (`id`) ) | 
[10:43:40] ProcessQueryThread() - Query was successful. (CREATE TABLE IF NOT EXISTS `users` (`id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(24) NOT NULL, `userpass` varchar(20) NOT NULL, `usermail` varchar(81) NOT NULL, `score` int(11) NOT NULL, `money` int(11) NOT NULL, PRIMARY KEY (`id`) ))
[10:43:40] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[10:44:03] >> mysql_query_callback( Connection handle: 1 )
[10:44:03] Passing query SELECT * FROM `users` WHERE `username` = 'Luca' LIMIT 1 | d
[10:44:03] ProcessQueryThread(OnCheckAccount) - Query was successful. (SELECT * FROM `users` WHERE `username` = 'Luca' LIMIT 1)
[10:44:03] ProcessQueryThread(OnCheckAccount) - Data caching enabled.
[10:44:03] CMySQLHandler::StoreResult() - Result was stored.
[10:44:03] CMySQLHandler::FreeResult() - Result was successfully free'd.
[10:44:03] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[10:44:03] OnCheckAccount(d) - Threaded function called.
[10:44:03] >> cache_get_data( Connection handle: 1 )
[10:44:03] ProcessTick() - The cache has been cleared.
[10:44:06] >> mysql_query_callback( Connection handle: 1 )
[10:44:06] Passing query INSERT INTO `users` (`username`, `userpass`, `usermail`, `score`, `money`) VALUES ('Luca', 'senha', '0', '0', '0') | ds
[10:44:06] ProcessQueryThread(OnPlayerInterMail) - Query was successful. (INSERT INTO `users` (`username`, `userpass`, `usermail`, `score`, `money`) VALUES ('Luca', 'senha', '0', '0', '0'))
[10:44:06] ProcessQueryThread(OnPlayerInterMail) - Data caching enabled.
[10:44:06] CMySQLHandler::StoreResult() - No data to store.
[10:44:06] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[10:44:06] OnPlayerInterMail(ds) - Threaded function called.
[10:44:06] ProcessTick() - The cache has been cleared.
[10:44:11] >> mysql_query_callback( Connection handle: 1 )
[10:44:11] Passing query UPDATE `users` SET 'usermail' = lucas@ig.com.br WHERE `username` = 'Luca' | ds
[10:44:11] CMySQLHandler::ProcessQueryThread() - Error will be triggered to OnQueryError()
Quote:
Originally Posted by Day_
Посмотреть сообщение
PHP код:
mysql_function_query(MysqlConnectquerytrue"OnPlayerRegistered""d"playerid
Estava passando uma string, agora que vim perceber.
Continua sem salvar

Log:

Код:
[11:09:23]  
[11:09:23]  ** MySQL Debugging enabled (10/27/15)
[11:09:23]  
[11:09:23] >> mysql_connect(localhost, root, sampserver, ******) on port 3306
[11:09:23] CMySQLHandler::CMySQLHandler() - constructor called.
[11:09:23] CMySQLHandler::CMySQLHandler() - Connecting to "localhost" | DB: "sampserver" | Username: "root"
[11:09:23] CMySQLHandler::Connect() - Connection was successful.
[11:09:23] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.
[11:09:23] >> mysql_ping( Connection handle: 1 )
[11:09:23] CMySQLHandler::Ping() - Connection is still alive.
[11:09:23] >> mysql_query_callback( Connection handle: 1 )
[11:09:23] Passing query CREATE TABLE IF NOT EXISTS `users` (`id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(24) NOT NULL, `userpass` varchar(20) NOT NULL, `usermail` varchar(81) NOT NULL, `score` int(11) NOT NULL, `money` int(11) NOT NULL, PRIMARY KEY (`id`) ) | 
[11:09:23] ProcessQueryThread() - Query was successful. (CREATE TABLE IF NOT EXISTS `users` (`id` int(11) NOT NULL AUTO_INCREMENT, `username` varchar(24) NOT NULL, `userpass` varchar(20) NOT NULL, `usermail` varchar(81) NOT NULL, `score` int(11) NOT NULL, `money` int(11) NOT NULL, PRIMARY KEY (`id`) ))
[11:09:23] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[11:09:44] >> mysql_query_callback( Connection handle: 1 )
[11:09:44] Passing query SELECT * FROM `users` WHERE `username` = 'Luca_Ferreira' LIMIT 1 | d
[11:09:44] ProcessQueryThread(OnCheckAccount) - Query was successful. (SELECT * FROM `users` WHERE `username` = 'Luca_Ferreira' LIMIT 1)
[11:09:44] ProcessQueryThread(OnCheckAccount) - Data caching enabled.
[11:09:44] CMySQLHandler::StoreResult() - Result was stored.
[11:09:44] CMySQLHandler::FreeResult() - Result was successfully free'd.
[11:09:44] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[11:09:44] OnCheckAccount(d) - Threaded function called.
[11:09:44] >> cache_get_data( Connection handle: 1 )
[11:09:44] ProcessTick() - The cache has been cleared.
[11:09:47] >> mysql_query_callback( Connection handle: 1 )
[11:09:47] Passing query INSERT INTO `users` (`username`, `userpass`, `usermail`, `score`, `money`) VALUES ('Luca_Ferreira', 'pq', '0', '0', '0') | ds
[11:09:47] ProcessQueryThread(OnPlayerInterMail) - Query was successful. (INSERT INTO `users` (`username`, `userpass`, `usermail`, `score`, `money`) VALUES ('Luca_Ferreira', 'pq', '0', '0', '0'))
[11:09:47] ProcessQueryThread(OnPlayerInterMail) - Data caching enabled.
[11:09:47] CMySQLHandler::StoreResult() - No data to store.
[11:09:47] CMySQLHandler::ProcessQueryThread() - Data is getting passed to ->ProcessTick()
[11:09:47] OnPlayerInterMail(ds) - Threaded function called.
[11:09:47] ProcessTick() - The cache has been cleared.
[11:10:04] >> mysql_query_callback( Connection handle: 1 )
[11:10:04] Passing query UPDATE `users` SET 'usermail' = lucas@ig.com.br WHERE `username` = 'Luca_Ferreira' | d
[11:10:04] CMySQLHandler::ProcessQueryThread() - Error will be triggered to OnQueryError()
EDIT: Resolvido obrigados a todo que tentaram me ajuda. IpsLeon era isso falta dos `` e '' vlw mano nem lembrava fazia tempo que nгo mexia com SA:MP.
Reply
#8

PHP код:
SET `usermail` = '%s' 
Reply
#9

Tenta desta forma, apesar de que as aspas nгo sгo um ponto crucial no MySQL.

PHP код:
format(querysizeof(query), "UPDATE `users` SET `usermail` = '%s' WHERE `username` = '%s'"inputtextReturnName(playerid)); 
Reply
#10

Esta й a mesma soluзгo proposta pelo Day_ porйm incorporei no cуdigo inicial publicado por vocк. Recomendo urgentemente vocк tratar os dados enviados via query!

O SEU CУDIGO ME PARECE SER VULNERБVEL A SQL INJECTION... NГO SEI SE ESTA INCLUDE QUE VOCК USA JБ TRATA OS DADOS.

pawn Код:
case dREGISTER:
    {
        if(!response) { SendClientMessage(playerid, 1, ""rRED"SERVER: Vocк foi expulso automaticamente."); return Kick(playerid); }
        else
        {
            if(strlen(inputtext) < 1 || strlen(inputtext) > 20) { ShowPlayerDialog(playerid, dREGISTER, DIALOG_STYLE_INPUT, ""rBLUE"REGISTRO", ""rWRITE"Bem Vindo ao \nVocк pode "rRED"registrar"rWRITE" uma conta, digitando uma senha desejada aqui:", ""rWRITE"Registrar", ""rWRITE"Sair"); }
            else
            {
                new query[200];
                format(query, sizeof(query), "INSERT INTO `users` (`username`, `userpass`, `usermail`, `score`, `money`) VALUES ('%s', '%s', '0', '0', '0')", ReturnName(playerid), inputtext);
                mysql_function_query(MysqlConnect, query, true, "OnPlayerInterMail", "ds", playerid);
            }
        }
    }
       
function OnPlayerInterMail(playerid)
{
    ShowPlayerDialog(playerid, dMAIL, DIALOG_STYLE_INPUT, ""rBLUE"E-MAIL", ""rWRITE"Inisira um e-mail vбlido, para o caso de precisar recuperar sua senha!", ""rWRITE"Inserir", ""rWRITE"Sair");
    return 1;
}

case dMAIL:
        {
            if(response)
            {
                if(strlen(inputtext) < 1 || strlen(inputtext) > 80) { ShowPlayerDialog(playerid, dMAIL, DIALOG_STYLE_INPUT, ""rBLUE"E-MAIL", ""rWRITE"Inisira um e-mail vбlido, para o caso de precisar recuperar sua senha!", ""rWRITE"Inserir", ""rWRITE"Sair"); }
                else
                {
                    new query[200];
                    format(query, sizeof(query), "UPDATE `users` SET usermail = '%s' WHERE `username` = '%s'", inputtext, ReturnName(playerid));
                    mysql_function_query(MysqlConnect, query, true, "OnPlayerRegistered", "ds", playerid);
                }
            }
        }
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)