SA-MP Forums

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

Reply
 
Thread Tools Display Modes
Old 04/08/2020, 02:31 AM   #11
Leaky
Big Clucker
 
Join Date: Jul 2018
Posts: 82
Reputation: 12
Default Re: Fixing MySQL log Error

Quote:
Originally Posted by Kwarde View Post
You are trying to insert (or inserting -if all columns may be NULL (thus NOT NULL not used)) a new row instead of updating the data of a row.

Also may I suggest you to store the IP as an integer?
Code:
CREATE TABLE isers(
    (columns...)
    Last_IP_Address INT UNSIGNED DEFAULT NULL, -- DEFAULT NULL so it doesn't need to be specified in the CREATE query
    (columns...)
) ENGINE = InnoDB;
Storing an IP:
pawn Code:
format(..., "UPDATE users SET Last_IP_Address = INET_ATON('%s') WHERE Name = '%s'", PlayerInfo[playerid][Last_IP_Address], GetName(playerid));
//or in insert ofc
format(..., "INSERT INTO users (..., IP_Address) VALUES (..., INET_ATON('%s') WHERE Name = '%s'", PlayerInfo[playerid][Last_IP_Address], GetName(playerid));
Fetching the IP:
pawn Code:
format(..., "SELECT INET_NTOA(IP_Address) AS IP_Address FROM users WHERE Name = '%s'", GetName(playerid));
new Cache:result = mysql_query(handle, query), ip[16];
cache_get_value_name(0, "IP_Address", ip);
INET_ATON changes an IP to an integer (ATON => Address To Number)
INET_NTOA changes an integer back to an IP (NTOA => Number To Address)
Column needs to be an INT UNSIGNED (some IP addressed otherwise would fall out of range).

I used "AS IP_Address" to make the result (cache) return it as IP_Address. Otherwise you would literally have to use "INET_NTOA(IP_Address)" in cache_get_value_name().
If you would want to select all data from a table you'd best approach it as:
Code:
SELECT *, INET_NTOA(Last_IP_Address) AS Last_IP_Address_Readable FROM users WHERE Name = 'someName';
Otherwise you'd have to write down all columns manually. This would return the IP (the readable ony) as Last_IP_Address_Readable. This method is faster and more efficient (and using less space) than storing whole strings.


EDIT:

Overlooked this. I never said it was a mistake (it is not at all). Just merely stating the fact it is not needed persay (some people don't seem to know this). Perhaps it's a personal thing but I don't like typing things if they're not needed.
To me, that's like doing:
pawn Code:
new bool:someBool = !!true;
new someInteger = ~~5;
It does exactly the same as (below) but it just has some extra unneeded characters.
pawn Code:
new bool:someBool = true;
new someInteger = 5;
Thank you very much I did like you instructed and it is storing the IP but it seems to be the wrong IP (255.255.255.255), Not my IP but I'm wondering if it's because it's a localhost. But thank you rep+ for you all.
__________________
Leaky 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
Please Help Me Fixing This Error WatchDog Server Support 23 31/03/2016 10:01 AM
I need help fixing this error Hakan Scripting Help 1 09/08/2014 05:20 AM
Help Fixing this error Zin Scripting Help 4 07/03/2014 11:03 AM
Need some help fixing this Error Blessed Server Support 0 22/05/2012 12:18 PM
[Help]Fixing A little Error Infinity90 Scripting Help 2 23/04/2012 05:52 PM


All times are GMT. The time now is 07:06 PM.


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