SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 03/01/2018, 06:55 PM   #1
Kraeror
Gangsta
 
Kraeror's Avatar
 
Join Date: Mar 2017
Location: Bulgaria
Posts: 534
Reputation: 19
Default MySQL R40 Problem

Help me pls!
I'm still learning this MySQL!
Here is my connection:
PHP Code:
sqlll mysql_connect("127.0.0.1""root""""sa-mp"); 
Here is my code:
PHP Code:
new query[256];
    
format(querysizeof(query), "INSERT INTO `houses`(`ID`, `Owner`, `Price`, `X`, `Y`, `Z`, `World`, `X2`, `Y2`, `Z2`, `A2`, `Int:X`, `Int:Y`, `Int:Z`, `Int:X2`, `Int:Y2`, `Int:Z2`, `Int:A2`, `Interior`, `Spawn:X`, `Spawn:Y`, `Spawn:Z`, `Spawn:A`, `Status`) VALUES (%d, %s, %d, %f, %f, %f, %d, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %f, %d, %f, %f, %f, %f, %d)",
    
hHouseInfo[h][hOwner], HouseInfo[h][hPrice], HouseInfo[h][hX], HouseInfo[hY], HouseInfo[h][hZ]);
    
mysql_query(sqlllquery); 
So the connection is tested and it works, but why there is nothing when I insert this values?
What I have to do before inserting this values? Please help me, +1 REP!
Kraeror is offline   Reply With Quote
Old 03/01/2018, 07:02 PM   #2
VincenzoDrift
Little Clucker
 
VincenzoDrift's Avatar
 
Join Date: Jun 2014
Posts: 47
Reputation: 3
Default Re: MySQL R40 Problem

Try with this query:
Code:
"INSERT INTO `houses`(`ID`, `Owner`, `Price`, `X`, `Y`, `Z`, `World`, `X2`, `Y2`, `Z2`, `A2`, `Int:X`, `Int:Y`, `Int:Z`, `Int:X2`, `Int:Y2`, `Int:Z2`, `Int:A2`, `Interior`, `Spawn:X`, `Spawn:Y`, `Spawn:Z`, `Spawn:A`, `Status`) VALUES ('%d', '%s', '%d', '%f', '%f', '%f', '%d', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%d', '%f', '%f', '%f', '%f', '%d')"
I have inserted ' ' between format specifiers %d, %s, ecc...
__________________
Sorry for my bad english
VincenzoDrift is offline   Reply With Quote
Old 03/01/2018, 07:05 PM   #3
Kraeror
Gangsta
 
Kraeror's Avatar
 
Join Date: Mar 2017
Location: Bulgaria
Posts: 534
Reputation: 19
Default Re: MySQL R40 Problem

Quote:
Originally Posted by VincenzoDrift View Post
Try with this query:
Code:
"INSERT INTO `houses`(`ID`, `Owner`, `Price`, `X`, `Y`, `Z`, `World`, `X2`, `Y2`, `Z2`, `A2`, `Int:X`, `Int:Y`, `Int:Z`, `Int:X2`, `Int:Y2`, `Int:Z2`, `Int:A2`, `Interior`, `Spawn:X`, `Spawn:Y`, `Spawn:Z`, `Spawn:A`, `Status`) VALUES ('%d', '%s', '%d', '%f', '%f', '%f', '%d', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%d', '%f', '%f', '%f', '%f', '%d')"
I have inserted ' ' between format specifiers %d, %s, ecc...
There is no changes in the database
Kraeror is offline   Reply With Quote
Old 03/01/2018, 07:09 PM   #4
VincenzoDrift
Little Clucker
 
VincenzoDrift's Avatar
 
Join Date: Jun 2014
Posts: 47
Reputation: 3
Default Re: MySQL R40 Problem

Ah your query string dimension is low.
Code:
new query[512];
__________________
Sorry for my bad english
VincenzoDrift is offline   Reply With Quote
Old 03/01/2018, 07:13 PM   #5
Kraeror
Gangsta
 
Kraeror's Avatar
 
Join Date: Mar 2017
Location: Bulgaria
Posts: 534
Reputation: 19
Default Re: MySQL R40 Problem

Quote:
Originally Posted by VincenzoDrift View Post
Ah your query string dimension is low.
Code:
new query[512];
Thanks for this! + 1 REP
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!REALY THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Kraeror is offline   Reply With Quote
Old 03/01/2018, 08:02 PM   #6
Logic_
Banned
 
Join Date: Jun 2015
Posts: 1,506
Reputation: 305
Default Re: MySQL R40 Problem

You should always escape strings and use threaded queries because they are faster and safer than non-threaded queries. Just %e to escape strings instead of %s and use mysql_tquery function instead of mysql_query. You can also use mysql_pquery if you just want to put data into the database etc.
Logic_ is offline   Reply With Quote
Old 03/01/2018, 08:22 PM   #7
DRIFT_HUNTER
High-roller
 
Join Date: Oct 2009
Posts: 2,152
Reputation: 215
Default Re: MySQL R40 Problem

I guess you fixed it, but keep in mind, your format function expects allot more variables then you actually provide, also you should use mysql_format for running queries instead of format.
DRIFT_HUNTER is offline   Reply With Quote
Old 04/01/2018, 05:59 PM   #8
Kraeror
Gangsta
 
Kraeror's Avatar
 
Join Date: Mar 2017
Location: Bulgaria
Posts: 534
Reputation: 19
Default Re: MySQL R40 Problem

Thank you guys, but there are more problems
Look: (the varibable h is used for house ID)
PHP Code:
new hcache_get_row_count(h);
new 
query[2048];
mysql_format(zMySQLquerysizeof(query), "INSERT INTO `houses`(`ID`, `Owner`, `Price`, `X`, `Y`, `Z`, `World`, `X2`, `Y2`, `Z2`, `A2`, `Int:X`, `Int:Y`, `Int:Z`, `Int:X2`, `Int:Y2`, `Int:Z2`, `Int:A2`, `Interior`, `Spawn:X`, `Spawn:Y`, `Spawn:Z`, `Spawn:A`, `Status`) VALUES ('%d', '%e', '%d', '%f', '%f', '%f', '%d', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%f', '%d', '%f', '%f', '%f', '%f', '%d')",
hHouseInfo[h][hOwner], HouseInfo[h][hPrice], HouseInfo[h][hX], HouseInfo[hY], HouseInfo[h][hZ], -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1);
mysql_tquery(zMySQLquery); 
Output: X: 151.123201, Y: 0, Z: 13.05541 and etc.
And it can't be loaded
Here is loading(OnGameModeInit callback):
PHP Code:
for(new 1MAX_HOUSESh++)
    {
        new 
house[64], query[1024];
        
mysql_format(zMySQLquerysizeof(query), "SELECT * FROM `houses` WHERE `ID` = %d"h);
          
mysql_tquery(zMySQLquery"LoadHouses""h");
        if(
strcmp(HouseInfo[h][hOwner], "No"true) == 0)
        {
            
HouseInfo[h][hPickup] = CreatePickup(12731HouseInfo[h][hX], HouseInfo[h][hY], HouseInfo[h][hZ]);
            
HouseInfo[h][hIcon] = CreateDynamicMapIcon(HouseInfo[h][hX], HouseInfo[h][hY], HouseInfo[h][hZ], 310,0,0);
        }
        else
        {
            
HouseInfo[h][hPickup] = CreatePickup(195221HouseInfo[h][hX], HouseInfo[h][hY], HouseInfo[h][hZ]);
            
HouseInfo[h][hIcon] = CreateDynamicMapIcon(HouseInfo[h][hX], HouseInfo[h][hY], HouseInfo[h][hZ], 320,0,0);
        }
    } 
and here is my LoadHouses callback:
PHP Code:
forward LoadHouses(houseid);
public 
LoadHouses(houseid)
{
    
cache_get_value_name(houseid"Owner"HouseInfo[houseid][hOwner]);
    
cache_get_value_name_float(houseid"X"HouseInfo[houseid][hX]);
    
cache_get_value_name_float(houseid"Y"HouseInfo[houseid][hY]);
    
cache_get_value_name_float(houseid"Z"HouseInfo[houseid][hZ]);
    
cache_get_value_name_float(houseid"Int:X"HouseInfo[houseid][hiX]);
    
cache_get_value_name_float(houseid"Int:Y"HouseInfo[houseid][hiY]);
    
cache_get_value_name_float(houseid"Int:Z"HouseInfo[houseid][hiZ]);
    
cache_get_value_name_float(houseid"X2"HouseInfo[houseid][hX2]);
    
cache_get_value_name_float(houseid"Y2"HouseInfo[houseid][hY2]);
    
cache_get_value_name_float(houseid"Z2"HouseInfo[houseid][hZ2]);
    
cache_get_value_name_float(houseid"A2"HouseInfo[houseid][hA2]);
    
cache_get_value_name_float(houseid"Int:X2"HouseInfo[houseid][hiX2]);
    
cache_get_value_name_float(houseid"Int:Y2"HouseInfo[houseid][hiY2]);
    
cache_get_value_name_float(houseid"Int:Z2"HouseInfo[houseid][hiZ2]);
    
cache_get_value_name_float(houseid"Int:A2"HouseInfo[houseid][hiA2]);
    
cache_get_value_name_float(houseid"Spawn:X"HouseInfo[houseid][hsX]);
    
cache_get_value_name_float(houseid"Spawn:Y"HouseInfo[houseid][hsY]);
    
cache_get_value_name_float(houseid"Spawn:Z"HouseInfo[houseid][hsZ]);
     
cache_get_value_name_float(houseid"Spawn:A"HouseInfo[houseid][hsA]);
    
cache_get_value_name_int(houseid"Interior"HouseInfo[houseid][hInt]);
    
cache_get_value_name_int(houseid"World"HouseInfo[houseid][hVW]);
    
cache_get_value_name_int(houseid"Price"HouseInfo[houseid][hPrice]);
    
cache_get_value_name_int(houseid"Status"HouseInfo[houseid][hStatus]);
    return 
1;

Kraeror is offline   Reply With Quote
Old 04/01/2018, 07:48 PM   #9
Kraeror
Gangsta
 
Kraeror's Avatar
 
Join Date: Mar 2017
Location: Bulgaria
Posts: 534
Reputation: 19
Default Re: MySQL R40 Problem

Any help please ?
Kraeror 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
Password Hash Problem & MYSQL Saving Problem Faqahat Scripting Help 3 18/04/2016 11:54 AM
[PLUGIN]: MySQL Problem (MYSQL R39-2) zT KiNgKoNg Scripting Help 11 11/11/2014 06:20 PM
[Mysql problem] Loss of communication with the mysql base SmileyCoder General 0 29/05/2014 03:38 PM
saving system mysql(not mysql problem) martoivanov Scripting Help 0 29/08/2013 03:37 PM
Problem with reading money from MySQL in "Clean, Simple MySQL GM" by L3th4l Dystans Help Archive 1 31/05/2011 09:19 PM


All times are GMT. The time now is 06:25 AM.


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