mysql creating table
#1

The problem is that it shows as NULL and doesnt display the name of adminlevel and skin, nor does it add a value like 299(skinid)

I messed around with int() and set it at int(10), that makes the names display in database instead of being blank.
What's the correct value to use for skin and adminlevel? max adminlevel would be 6.
pawn Код:
mysql_function_query(g_Handle, "CREATE TABLE IF NOT EXISTS `users` ( \
        `id` int(11) NOT NULL AUTO_INCREMENT, \
        `name` varchar(24) NOT NULL, \
        `pass` varchar(129) NOT NULL, \
        `salt` varchar(30) NOT NULL, \
        `health` float NOT NULL, \
        `armor` float NOT NULL, \
        `X` float NOT NULL, \
        `Y` float NOT NULL, \
        `Z` float NOT NULL, \
        `A` float NOT NULL, \
        `interior` int(2) NOT NULL, \
        `vw` int(11) NOT NULL, \
        `skin` int(3) NOT NULL, \
        `adminlevel` int(2) NOT NULL, \
        PRIMARY KEY (`id`) \
    )"
, false, "SendQuery", "");

The save code incase there's an error there.
Код:
stock SaveAccount(playerid)
{
	new 
		query[600],
		Float:pos[4],
		Float:health,
		Float:armor;
	
	GetPlayerPos(playerid, posArr{pos});
	GetPlayerFacingAngle(playerid, pos[3]);
	GetPlayerHealth(playerid, health);
	GetPlayerArmour(playerid, armor);
	
	format(query, sizeof(query), "UPDATE `users` SET health = %.1f, armor = %.1f, X = %.2f, Y = %.2f, Z = %.2f, A = %.2f, interior = %d, vw = %d, skin = %d, adminlevel = %d WHERE `id` = %d",
		health,
		armor,
		posArrEx{pos},
		GetPlayerInterior(playerid),
		GetPlayerVirtualWorld(playerid),
		GetPlayerSkin(playerid),
		g_PlayerInfo[playerid][pAdminLevel],
		g_PlayerInfo[playerid][pSQLid]
	);
	
	mysql_function_query(g_Handle, query, false, "SendQuery", "");
	return 1;
}
Reply
#2

Create your table in phpMyAdmin (usually at http://localhost/phpmyadmin), where you can actually see what's wrong.
Reply
#3

Quote:
Originally Posted by Sinner
Посмотреть сообщение
Create your table in phpMyAdmin (usually at http://localhost/phpmyadmin), where you can actually see what's wrong.
What does int(number) define?

int(3) doesnt work for skin but when I put it at 4 it works fine and saves..
Reply
#4

The number in brackets doesn't actually define anything. As far as I know, it is only used with the option 'zerofill' to pad it to the specified length. For example: 001. See here for what integer type to use: http://dev.mysql.com/doc/refman/5.0/...ger-types.html
Reply
#5

Okay thanks, working fine right now.
Another question

What's wrong with this code?, I got loading working when manually entering weaponids etc, but saving seems a bit trickier.
I've no idea if [MAX_PLAYERS] is really needed, I tried w/ and w/o.
pawn Код:
stock SavePlayerWeapons(playerid)
{
    new
        query[300],
        weapon0[MAX_PLAYERS],
        ammo0[MAX_PLAYERS],
        weapon1[MAX_PLAYERS],
        ammo1[MAX_PLAYERS];
       
    GetPlayerWeaponData(playerid, 0, weapon0[playerid], ammo0[playerid]);
    GetPlayerWeaponData(playerid, 1, weapon1[playerid], ammo1[playerid]);
    format(query, sizeof(query), "UPDATE `users` SET weapon0 = %d, ammo0 = %d, weapon1 = %d, ammo1 = %d WHERE `id` = %d",
    weapon0,
    ammo0,
    weapon1,
    ammo1
    );
    mysql_function_query(g_Handle, query, false, "SendQuery", "");
   
    return 1;
}
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)