Mysql doesn't insert player data to database
#1

Hi guys, I'm learning MySQL and I get this error. I'm doing a registration system with MySQL to save the player data. But the problem is when the player register, it doesn't insert anything to my database.
PHP Code:
new pName[MAX_PLAYER_NAME], query[256];
    
GetPlayerName(playeridpNamesizeof(pName));
    
mysql_format(MHandlequerysizeof(query), "SELECT * FROM `character` WHERE `Username` = '%e' LIMIT 1"pName);
    
mysql_query(MHandlequery);
    new 
rows;
    
cache_get_row_count(rows);
    if(!
rows){
        
System_Scm(playeridCOLOR_YELLOW"REGISTER""You can register.");
        
//SetupCharacter(playerid);    
        
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_PASSWORD"Registration""Fill your password into the box below""Okay""Cancel");
    } 
PHP Code:
case DIALOG_REGISTER:{
            if(
response){
                if(!
response) return Kick(playerid); 
                if(!
strlen(inputtext) || strlen(inputtext) > 100){
                    
System_Scm(playeridCOLOR_RED"ERROR""Password must be at least 5 words and lower than 100 words.");
                    
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_PASSWORD"Registration""Fill your password into the box below to register your account""Ok""Cancel");
                } 
                else if(
strlen(inputtext) > && strlen(inputtext) < 100
                {
                    new 
pName[MAX_PLAYER_NAME], query[256];
                    new 
Cache:GetCache;
                    
GetPlayerIp(playeridCharacter[playerid][IP], 16);
                    
mysql_format(MHandlequerysizeof(query), "INSERT INTO `character` (`Username`, `Password`, `Level`, `Money`, `IP`, `posX`, `posY`, `posZ`, `posA`, `Health`, `Armour`) VALUES ('%s', 'SHA1(%s)', (1), (10000), '%s', (1958.3783), (1343.1572), (15.3746), (90.0), (100.0), (0.0))"pNameinputtextCharacter[playerid][IP]);
                    
GetCache mysql_query(MHandlequery);
                    
cache_delete(GetCache);
                    
System_Scm(playeridCOLOR_YELLOW"REGISTERED""You have registered succesfully!");
                    
SpawnPlayer(playerid);
                }
            }
        } 
Reply
#2

Image of my database.
Reply
#3

Below ongamemodeinit write:

Code:
mysql_log(LOG_ALL);
Then starts the server, try to register an account and paste here the log on mysql_log.txt in your samp server folder
Reply
#4

Quote:
Originally Posted by pollo97
View Post
Below ongamemodeinit write:

Code:
mysql_log(LOG_ALL);
Then starts the server, try to register an account and paste here the log on mysql_log.txt in your samp server folder
Quote:

error 017: undefined symbol "LOG_ALL"

I got this error @@!
Reply
#5

I didn't use mysql_log but I got this two lines in the mysql logs.
Quote:

[21:39:40] [ERROR] mysql_format: destination size '256' is too small
[21:39:40] [ERROR] error #1065 while executing query "": Query was empty

Reply
#6

But I have increased the size of 'query' from 256 up to 512. And there was no empty query.
Reply
#7

change your query

try it

PHP Code:
mysql_format(MHandlequerysizeof(query), "INSERT INTO `character` (`Username`, `Password`, `Level`, `Money`, `IP`, `posX`, `posY`, `posZ`, `posA`, `Health`, `Armour`)\
 VALUES ('%s', 'SHA1(%s)', 1, 10000, '%s', 1958.3783, 1343.1572, 15.3746, 90.0, 100.0, 0.0)"
pNameinputtextCharacter[playerid][IP]); 
if use plugin MySQL R41-2 mysql_log(LOG_ALL); change by mysql_log(ALL);
Reply
#8

Thank you, I have fix it. Thanks for the help, this is my code.
Quote:

mysql_format(MHandle, query, sizeof(query), "INSERT INTO `character` (`Username`, `Password`, `Level`, `Money`, `IP`, `posX`, `posY`, `posZ`, `posA`, `Health`, `Armour`) VALUES ('%s', SHA1('%s'), 1, 10000, '%s', 1958.3783, 1343.1572, 15.3746, 90.0, 100.0, 0.0)", pName, inputtext, Character[playerid][IP]);

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)