SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 21/01/2020, 08:11 PM   #1
diltx
Little Clucker
 
Join Date: Jan 2020
Posts: 1
Reputation: 0
Cool MySQL not uploading data to my database, XAMPP

Hello, i am new to MySQL and i am testing a MySQL code for a SA-MP server.
I am using XAMPP and MySQL-R41-4 plugin.

The server connects successfully to database according to the console and there are no errors in server log. But when i try to upload information with a server command to an already created table in the database, it doesn´t upload at all.

This is the code:
PHP Code:
#include <a_samp>
#include <a_mysql>


// * Define connection credentials. */
#define MYSQL_HOST "localhost"  
#define MYSQL_USER "root"  
#define MYSQL_PASS ""  
#define MYSQL_DB   "sa-mp_blueprint"  

new MySQLOpt:my_options// Notice the "MySQLOpt" tag. 
new MySQL:db_handle;

main()
{
    print(
"\n---------------------------------------");
    print(
"Running MySQL_blueprint \n");
    print(
"---------------------------------------\n");
}

forward OnGameModeInit();
public 
OnGameModeInit()  
{  
    
/* Create a set of options and store the ID. */ 
    
my_options mysql_init_options();  

    
/* Define connection options for the created set. */ 
    
mysql_set_option(my_optionsAUTO_RECONNECTtrue);  
    
mysql_set_option(my_optionsMULTI_STATEMENTSfalse);  
    
mysql_set_option(my_optionsPOOL_SIZE2);  
    
mysql_set_option(my_optionsSERVER_PORT3306);  

    
/* Connect to the database using the defined credentials and options. */ 
    
mysql_connect(MYSQL_HOSTMYSQL_USERMYSQL_PASSMYSQL_DBmy_options);  
 
    
//mysql_errno(db_handle)
    
if(mysql_errno() !=0)
    {
      
printf("[MySQL]:Connection to database not sucessful");
    
    }
    else
    {
      
printf("[MySQL]:Connection to database sucessful");     

    }
    return 
1;

}  


public 
OnPlayerCommandText(playeridcmdtext[])
{
// it seems like ` and ' have the same function.
    
new stringq[60];
    new 
datainserted[15]= "carro volador?";
    new 
Float:a;
    
333.45 ;
 

    if (!
strcmp(cmdtext"/kill"true))
    {
    
SetPlayerHealth(playerid0);
    return 
1;
    
    
    }
    if (!
strcmp(cmdtext"/insertdata"true))
    {
    
mysql_format(db_handlestringqsizeof(stringq), "INSERT INTO `nube` (`name`, `password`) VALUES (%s, %d)""string test"1.345);
    
mysql_query(db_handlestringq);
   
    return 
1;
    
    
    }
    
    if (!
strcmp(cmdtext"/updatedata"true))
    {
    
mysql_format(db_handlestringqsizeof(stringq),"UPDATE `nube` SET `name` = %s, `password`= %d"datainserteda);
    
mysql_query(db_handlestringq);
 
    return 
1;
    
    
    }

    

    return 
0;
}

public 
OnGameModeExit()  
{  
    
//* - close the connection on exit. */  
    
if(db_handle)  
    {  
        
mysql_close(db_handle);  
    }  
    return 
1;  

I appreciate your help and thank you for helping SAMP keep growing and promoting gameplay fun.
diltx is offline   Reply With Quote
Old 21/01/2020, 08:27 PM   #2
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 958
Reputation: 167
Default Re: MySQL not uploading data to my database, XAMPP

logs\plugins\mysql.log file should be more detailed.

The size of `stringq` is small, make it at least 70+
Always use single quotes for text, change to '%s' (or '%e' if you escape any user input to avoid sql injection).
What datatype `password` column is? You try to insert a float, you try to update it as an integer but its name indicates text.
__________________
Calisthenics is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Xampp mysql unable to connect to database? ax1 Scripting Help 2 12/03/2017 07:20 PM
MySQL Load Data From Database lewismichaelbbc Scripting Help 0 19/06/2014 03:47 PM
Data from MySQL Database not doing it's job Shoulen Scripting Help 5 04/04/2013 04:53 PM
[HELP] Getting data from MySQL database ???? cAMo Help Archive 17 11/11/2009 03:28 PM
MYSQL - Reading data from Database joshAllan Help Archive 4 14/10/2009 12:46 PM


All times are GMT. The time now is 11:56 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.