Help please guys!
#1

Hello everyone, today I'm facing a problem with mysql (Register System), it doesn't create an account on Database
Here's the details : (I'm using R39-4, guys)

PHP код:
#define SQL_HOSTNAME "127.0.0.1"
#define SQL_USERNAME "root"
#define SQL_DATABASE "srvdata"
#define SQL_PASSWORD ""
forward SQL_Connect(); //Here's the connection mysql
public SQL_Connect()
{
    
SQL mysql_connect(SQL_HOSTNAMESQL_USERNAMESQL_DATABASESQL_PASSWORD);
    
printf("Connecting MYSQL"); //It appears on log
    
return 1;

PHP код:
Dialog:Register(playeridresponselistiteminputtext[])
{
    if(!
response || !strlen(inputtext))
    {
        
SendClientMessage(playeridCOULEUR_GRIS,"Veuillez mettrer un mot de passe..");
        
Kick(playerid);
        return 
1;
    }
        else if(
strlen(inputtext) > 4)
    {
        new 
query[400];
            
mysql_format(SQLquerysizeof(query), "INSERT INTO srv_users (Username, Password) VALUES ('%e','%e')",ReturnName(playerid), inputtext);
        
mysql_tquery(SQLquery,"","");
        
printf("%s"query); //It appears on log
    
}
    return 
1;

When I check 'srv_users' I don't see any account.
Visibly, I see that everything is correct, I don't really know what's wrong
Any question please I'm here

Logs:

Код:
[17:05:54] [connection] incoming connection: 127.0.0.1:64888 id: 0
[17:05:55] [join] Usaki_Mortsi has joined the server (0:127.0.0.1)
[17:06:00] INSERT INTO srv_users (Username, Password) VALUES('Usaki_Mortsi','mdpduserv')
[17:07:37] [part] Usaki_Mortsi has left the server (0:1)
Reply
#2

This is not the way to say that the connection was actually successful. See: https://sampwiki.blast.hk/wiki/MySQL/R33#mysql_errno

Check your mysql logs for any error, the connection handle might be invalid (could not connect).

Also consider hashing the passwords + salt for security. Plain text for them is really bad.
Reply
#3

That's true! But the connection of Mysql is certainly successful, while I get the dialog of registration.
And yeah @Konstantinos I tried 'mysql_errno', I found on logs that it's loaded.
I think the problem is here :
PHP код:
mysql_format(SQLquerysizeof(query), "INSERT INTO srv_users (Username, Password) VALUES ('%e','%e')",ReturnName(playerid), inputtext); 
Reply
#4

Make sure you write the tabel name "srv_users" correct and the check if columns exist in tabel, "Username" and "Password". You need to use the same letters (CAPS or NO-CAPS), this can modifie the ASCII and I think it could give u an error.
Reply
#5

I really hope if it was something like this..
But as you see at the pictures
Reply
#6

Find mysql_log.txt and delete the file (unless HTML is supported, I think it is no longer). Set:
pawn Код:
mysql_log(LOG_ALL);
Start the server again and try to register a new account. Check again the mysql logs - that's the only way to know what is wrong.
Reply
#7

I have done what you requested me @Konstantinos

Quote:

[22:57:28] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[22:57:28] [ERROR] CMySQLQuery::Execute[] - (error #1064) Erreur de syntaxe prиs de '(ID, Username, Password) VALUES (0, 'Usaki_Mortsi', 'lslsl')' а la ligne 1
[22:57:28] [DEBUG] CMySQLQuery::Execute[] - error will be triggered in OnQueryError

Sincerely, I don't see what the error want to say..?
I'm using this script right now

PHP код:
        static
        
query[512];
        
mysql_format(g_iHandlequerysizeof(query), "INSERT INTO `srv_users` (ID, Username, Password) VALUES (%d, '%e', '%e')",cache_insert_id(), ReturnName(playerid), inputtext);
        
mysql_tquery(g_iHandlequery);
        
mysql_log(LOG_ALL); 
EDIT: Thanks to this thread, I resolved this problem, at the same time I got another one

Quote:

[23:12:04] [DEBUG] CMySQLQuery::Execute[] - starting query execution
[23:12:04] [ERROR] CMySQLQuery::Execute[] - (error #1054) Champ 'Usaki_Mortsi' inconnu dans field list
[23:12:04] [DEBUG] CMySQLQuery::Execute[] - error will be triggered in OnQueryError

So here I am stuck
Reply
#8

mysql_log should be executed once before the mysql_connect line. cache_insert_id() returns 0 because no active cache (should be used in a specified callback at mysql_tquery) like this:
pawn Код:
mysql_format(g_iHandle, query, sizeof(query), "INSERT INTO `srv_users` (Username, Password) VALUES ('%e', '%e')", ReturnName(playerid), inputtext);
mysql_tquery(g_iHandle, query, "OnPlayerRegister", "i", playerid);
pawn Код:
forward OnPlayerRegister(playerid);
public OnPlayerRegister(playerid)
{
    // cache_insert_id() will return the "ID" if the field has been set..
    // as AUTO_INCREMENT, must also be set as PRIMARY key
}
---

About the last, Usaki_Mortsi is unknown column to your database. Create it or check if you misspelled it.
Reply
#9

I really appreciate your help @Konstantinos with me
Problem is solved, thank you really Konstantinos!
+1
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)