Server returns 'Unknown command' when creating MySQL houses.
#1

Hello guys, I learnt MySQL about 2 days earlier, and tried doing this. (I know it's a copy paste of a tutorial about creating houses, modified to a MySQL database)

The PAWN code, with my variables: (You might find my MySQL scripting quite poor, read above for the reason!
pawn Код:
CMD:createhouse(playerid,params[])
{
new HousePrice,id = HouseCount;
if(PlayerInfo[playerid][pLevel]>=5 || IsPlayerAdmin(playerid))
{
//Creating the house price for the selected value in the command, and the last house id created.
    if(sscanf(params,"i",HousePrice)) return SendClientMessage(playerid,COLOR_RED,"USAGE: /createhouse <price>");//Checking if the player uses the correct syntax. The parameter "i" in sscanf means integer, also could be used as "d".
        {
        new Float:x,Float:y,Float:z; new st[300]; new labelstring[128];//Creating the floats, to store the player's position.
        GetPlayerPos(playerid,x,y,z);//Getting the player's position and storing it
        hInfo[id][Price] = HousePrice;//Setting the house price to the selected one.
        hInfo[id][Owned] = 0;//Setting the house id owned = 0
        hInfo[id][XPos] = x;//Storing the XPos value to the player's x.
        hInfo[id][YPos] = y;//Storing the YPos value to the player's y.
        hInfo[id][ZPos] = z;//Storing the ZPos value to the player's z.
        hInfo[id][VirtualWorld] = GetPlayerVirtualWorld(playerid);
        format(hInfo[id][Owner],24,"Nonusablenameforthishou");
        format(labelstring,sizeof(labelstring),"~g~For Sale! \nPrice:~b~ $%i.",HousePrice);
        hInfo[id][HouseLabel] = Create3DTextLabel(labelstring,0xFF0000FF,x,y,z,25.0,GetPlayerVirtualWorld(playerid));
        [B]format(st,300,"INSERT INTO `houses`(Owner, Price, Owned, xpos, ypos, zpos, virtualworld, labeltext) VALUES ('%s', '%i', '%d', '%f', '%f', '%f', '%i', '%s')", hInfo[id][Owner],HousePrice, 0 , hInfo[id][XPos],hInfo[id][YPos],hInfo[id][ZPos],hInfo[id][VirtualWorld],hInfo[id][HouseLabel]);[/B]
        mysql_query(st);
        format(st,300,"House created. ID: %d",id);
        SendClientMessage(playerid,COLOR_GREEN,st);
        HouseEnter[id] = CreateDynamicCP(x,y,z,1.5,GetPlayerVirtualWorld(playerid));//Creating the checkpoint and storing it in the HouseEnter value.
        HouseExit[id] = CreateDynamicCP(443.9237,509.4609,1001.4195,1.5,GetPlayerVirtualWorld(playerid));//Creating the house exit checkpoint and storing it in the HouseExit value.
        HouseCount++;
        }
}
else return SendClientMessage(playerid,COLOR_ORANGERED,notknown);
//notknown is my custom error message predefined @ the top of the script.
return 1;
}
The line where I create the database:
pawn Код:
mysql_query("CREATE TABLE IF NOT EXISTS Houses(Owner VARCHAR(24), Owned INT(1), Price INT(7), xpos FLOAT(9), ypos FLOAT(9),zpos FLOAT(9), virtualworld INT(2), labeltext VARCHAR(300))");
Problem 1: What should happen: It should create a house at my current pos, with the price defined with all others set to 0.
What happens: It returns me my custom OnPlayerCommandText error message. (The command...)

Problem 2:
The script, on compiling gives warning on the line that is in bold text above, the warning is 'tag mismatch.' And no, I am using floats and all, when I remove 'labeltext' from the line, the warning vanishes, so I think the problem is with it.
The table:

The Debug log:
Код:
[16:23:19]  

[16:23:19] ---------------------------

[16:23:19] MySQL Debugging activated (12/13/12)

[16:23:19] ---------------------------

[16:23:19]  

[16:23:19] >> mysql_connect( )

[16:23:19] CMySQLHandler::CMySQLHandler() - constructor called.

[16:23:19] CMySQLHandler::CMySQLHandler() - Connecting to "localhost" | DB: "database" | Username: "root" ...

[16:23:19] CMySQLHandler::Connect() - Connection was successful.

[16:23:19] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.

[16:23:19] >> mysql_query( Connection handle: 1 )

[16:23:19] CMySQLHandler::Query(CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(40), score INT(20), money INT(20), level INT(20), vip INT(20), kma INT(20), rank INT(20), kills INT(20), deaths INT(20), muted INT(20), jailed INT(20), frozen INT(20), mutedtimes INT(20), jailedtimes INT(20), frozentimes INT(20), logins INT(20), posx INT(20), posy INT(20), posz INT(20), posa INT(20), IP VARCHAR(15) )) - Successfully executed.

[16:23:19] >> mysql_query( Connection handle: 1 )

[16:23:19] CMySQLHandler::Query(CREATE TABLE IF NOT EXISTS Bans(Username VARCHAR(32), Admin VARCHAR(32), IP VARCHAR(16), Reason VARCHAR(64), Seconds INT(12), Banned INT(5) )) - Successfully executed.

[16:23:19] >> mysql_query( Connection handle: 1 )

[16:23:19] CMySQLHandler::Query(CREATE TABLE IF NOT EXISTS `playerhouses`( `id` int(20) NOT NULL AUTO_INCREMENT,Owner VARCHAR(24) DEFAULT NULL, Owned INT(1) DEFAULT NULL, Price INT(7) DEFAULT NULL, xpos FLOAT(9) DEFAULT NULL, ypos FLOAT(9) DEFAULT NULL,zpos FLOAT(9) DEFAULT NULL , virtualworld INT(2) DEFAULT NULL, labeltext VARCH) - An error has occured. (Error ID: 1064, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCH' at line 1)

[16:23:19]  

[16:23:19] ---------------------------

[16:23:19] MySQL Debugging activated (12/13/12)

[16:23:19] ---------------------------

[16:23:19]  

[16:23:50] >> mysql_query( Connection handle: 1 )

[16:23:50] CMySQLHandler::Query(SELECT * FROM `Bans` WHERE (`Username` = 'Rajat_pawaR' OR `IP` = '127.0.0.1') AND `Banned` = 1 LIMIT 1) - Successfully executed.

[16:23:50] >> mysql_store_result( Connection handle: 1 )

[16:23:50] CMySQLHandler::StoreResult() - Result was stored.

[16:23:50] >> mysql_num_rows( Connection handle: 1 )

[16:23:50] CMySQLHandler::NumRows() - Returned 0 row(s)

[16:23:50] >> mysql_free_result( Connection handle: 1 )

[16:23:50] CMySQLHandler::FreeResult() - Result was successfully free'd.

[16:23:50] >> mysql_query( Connection handle: 1 )

[16:23:50] CMySQLHandler::Query(SELECT IP FROM `playerdata` WHERE user = 'Rajat_pawaR' LIMIT 1) - Successfully executed.

[16:23:50] >> mysql_store_result( Connection handle: 1 )

[16:23:50] CMySQLHandler::StoreResult() - Result was stored.

[16:23:50] >> mysql_num_rows( Connection handle: 1 )

[16:23:50] CMySQLHandler::NumRows() - Returned 1 row(s)

[16:23:50] >> mysql_fetch_field_row( Connection handle: 1 )

[16:23:50] CMySQLHandler::FetchField(IP) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[16:23:50] >> mysql_free_result( Connection handle: 1 )

[16:23:50] CMySQLHandler::FreeResult() - Result was successfully free'd.

[16:24:06] >> mysql_real_escape_string( Connection handle: 1 )

[16:24:06] CMySQLHandler::EscapeString(mypass); - Escaped 9 characters to mypass.

[16:24:06] >> mysql_query( Connection handle: 1 )

[16:24:06] CMySQLHandler::Query(SELECT `user` FROM playerdata WHERE user = 'Rajat_pawaR' AND password = SHA1('mypass')) - Successfully executed.

[16:24:06] >> mysql_store_result( Connection handle: 1 )

[16:24:06] CMySQLHandler::StoreResult() - Result was stored.

[16:24:06] >> mysql_num_rows( Connection handle: 1 )

[16:24:06] CMySQLHandler::NumRows() - Returned 1 row(s)

[16:24:06] >> mysql_query( Connection handle: 1 )

[16:24:06] CMySQLHandler::Query(SELECT score, money, level, vip, kma, rank, kills, deaths, muted, jailed, frozen, mutedtimes, jailedtimes, frozentimes, banned, bannedby, logins, posx, posy, posz, posa FROM playerdata WHERE user = 'Rajat_pawaR') - Successfully executed.

[16:24:06] >> mysql_store_result( Connection handle: 1 )

[16:24:06] CMySQLHandler::StoreResult() - Result was stored.

[16:24:06] >> mysql_fetch_row_format( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchRow() - Return: 0|0|16|0|0|0|0|0|0|0|0|0|0|0|0||46|127|-64|2|315

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("score") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("money") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("level") - 16

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("vip") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("kma") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("rank") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("kills") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("deaths") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("muted") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("jailed") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("frozen") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("mutedtimes") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("jailedtimes") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("frozentimes") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("logins") - 46

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("posx") - 127

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("posy") - -64

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("posz") - 2

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("posa") - 315

[16:24:06] >> mysql_fetch_row_format( Connection handle: 1 )

[16:24:06] >> mysql_free_result( Connection handle: 1 )

[16:24:06] CMySQLHandler::FreeResult() - Result was successfully free'd.

[16:24:06] >> mysql_free_result( Connection handle: 1 )

[16:24:06] CMySQLHandler::FreeResult() - The result is already empty.
I would appreciate it a lot if you help because this is driving me up the wall now.
Thank you,
Rajat.
Reply
#2

Any good MySQL scripters, care to help me? Thanks in advance!
Reply
#3

First of all! Where is the ID of the house is getting stored? You missed to save the id of the house and make it Primary for the table and set it AUTO_INCREMENT!

This is how you should create the Table.

pawn Код:
format(query,sizeof(query),"CREATE TABLE IF NOT EXISTS `Houses`( `id` int(20) NOT NULL AUTO_INCREMENT,Owner VARCHAR(24) DEFAULT NULL, Owned INT(1) DEFAULT NULL, Price INT(7) DEFAULT NULL, xpos FLOAT(9) DEFAULT NULL\
    , ypos FLOAT(9) DEFAULT NULL,zpos FLOAT(9) DEFAULT NULL \
    , virtualworld INT(2) DEFAULT NULL, labeltext VARCHAR(300) DEFAULT NULL,PRIMARY KEY (`id`))"
);
    mysql_query(query);
Reply
#4

Oh, thanks, replaced it. But still the goddamn command returns Unknown Command. And this is starting to frustrate me, lol.
Reply
#5

Try replacing this;

PHP код:
('%s''%i''%d''%f''%f''%f''%i''%s'
with
PHP код:
('%s', %d, %d'%f''%f''%f', %d'%s'
Reply
#6

Quote:
Originally Posted by Roel
Посмотреть сообщение
Try replacing this;

PHP код:
('%s''%i''%d''%f''%f''%f''%i''%s'
with
PHP код:
('%s', %d, %d'%f''%f''%f', %d'%s'
To no use, still returns the unknown command, though, thanks a lot for trying to help!
To others: if you need any other part of the script to try and help me, please do ask.
Reply
#7

Ok, enabled mysql debugger, add mysql_debug(1); in your ongamemodeinit, and restart the server, then run this script, and send us the last log lines that are inside the mysql_log.txt inside your server root.

Also you can try inserting a query with the phpmyadmin tool, if this also not works then your database structure is the cause.

edit; And you can show me your define of HouseLabel.
Reply
#8

Already had enabled it, *FACEPALM* To me, should've provided the log.
Код:
[16:23:19]  

[16:23:19] ---------------------------

[16:23:19] MySQL Debugging activated (12/13/12)

[16:23:19] ---------------------------

[16:23:19]  

[16:23:19] >> mysql_connect( )

[16:23:19] CMySQLHandler::CMySQLHandler() - constructor called.

[16:23:19] CMySQLHandler::CMySQLHandler() - Connecting to "localhost" | DB: "database" | Username: "root" ...

[16:23:19] CMySQLHandler::Connect() - Connection was successful.

[16:23:19] CMySQLHandler::Connect() - Auto-Reconnect has been enabled.

[16:23:19] >> mysql_query( Connection handle: 1 )

[16:23:19] CMySQLHandler::Query(CREATE TABLE IF NOT EXISTS playerdata(user VARCHAR(24), password VARCHAR(40), score INT(20), money INT(20), level INT(20), vip INT(20), kma INT(20), rank INT(20), kills INT(20), deaths INT(20), muted INT(20), jailed INT(20), frozen INT(20), mutedtimes INT(20), jailedtimes INT(20), frozentimes INT(20), logins INT(20), posx INT(20), posy INT(20), posz INT(20), posa INT(20), IP VARCHAR(15) )) - Successfully executed.

[16:23:19] >> mysql_query( Connection handle: 1 )

[16:23:19] CMySQLHandler::Query(CREATE TABLE IF NOT EXISTS Bans(Username VARCHAR(32), Admin VARCHAR(32), IP VARCHAR(16), Reason VARCHAR(64), Seconds INT(12), Banned INT(5) )) - Successfully executed.

[16:23:19] >> mysql_query( Connection handle: 1 )

[16:23:19] CMySQLHandler::Query(CREATE TABLE IF NOT EXISTS `playerhouses`( `id` int(20) NOT NULL AUTO_INCREMENT,Owner VARCHAR(24) DEFAULT NULL, Owned INT(1) DEFAULT NULL, Price INT(7) DEFAULT NULL, xpos FLOAT(9) DEFAULT NULL, ypos FLOAT(9) DEFAULT NULL,zpos FLOAT(9) DEFAULT NULL , virtualworld INT(2) DEFAULT NULL, labeltext VARCH) - An error has occured. (Error ID: 1064, You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'VARCH' at line 1)

[16:23:19]  

[16:23:19] ---------------------------

[16:23:19] MySQL Debugging activated (12/13/12)

[16:23:19] ---------------------------

[16:23:19]  

[16:23:50] >> mysql_query( Connection handle: 1 )

[16:23:50] CMySQLHandler::Query(SELECT * FROM `Bans` WHERE (`Username` = 'Rajat_pawaR' OR `IP` = '127.0.0.1') AND `Banned` = 1 LIMIT 1) - Successfully executed.

[16:23:50] >> mysql_store_result( Connection handle: 1 )

[16:23:50] CMySQLHandler::StoreResult() - Result was stored.

[16:23:50] >> mysql_num_rows( Connection handle: 1 )

[16:23:50] CMySQLHandler::NumRows() - Returned 0 row(s)

[16:23:50] >> mysql_free_result( Connection handle: 1 )

[16:23:50] CMySQLHandler::FreeResult() - Result was successfully free'd.

[16:23:50] >> mysql_query( Connection handle: 1 )

[16:23:50] CMySQLHandler::Query(SELECT IP FROM `playerdata` WHERE user = 'Rajat_pawaR' LIMIT 1) - Successfully executed.

[16:23:50] >> mysql_store_result( Connection handle: 1 )

[16:23:50] CMySQLHandler::StoreResult() - Result was stored.

[16:23:50] >> mysql_num_rows( Connection handle: 1 )

[16:23:50] CMySQLHandler::NumRows() - Returned 1 row(s)

[16:23:50] >> mysql_fetch_field_row( Connection handle: 1 )

[16:23:50] CMySQLHandler::FetchField(IP) - You cannot call this function now. (Reason: Fields/Rows are empty.)

[16:23:50] >> mysql_free_result( Connection handle: 1 )

[16:23:50] CMySQLHandler::FreeResult() - Result was successfully free'd.

[16:24:06] >> mysql_real_escape_string( Connection handle: 1 )

[16:24:06] CMySQLHandler::EscapeString(120996Rox); - Escaped 9 characters to 120996Rox.

[16:24:06] >> mysql_query( Connection handle: 1 )

[16:24:06] CMySQLHandler::Query(SELECT `user` FROM playerdata WHERE user = 'Rajat_pawaR' AND password = SHA1('120996Rox')) - Successfully executed.

[16:24:06] >> mysql_store_result( Connection handle: 1 )

[16:24:06] CMySQLHandler::StoreResult() - Result was stored.

[16:24:06] >> mysql_num_rows( Connection handle: 1 )

[16:24:06] CMySQLHandler::NumRows() - Returned 1 row(s)

[16:24:06] >> mysql_query( Connection handle: 1 )

[16:24:06] CMySQLHandler::Query(SELECT score, money, level, vip, kma, rank, kills, deaths, muted, jailed, frozen, mutedtimes, jailedtimes, frozentimes, banned, bannedby, logins, posx, posy, posz, posa FROM playerdata WHERE user = 'Rajat_pawaR') - Successfully executed.

[16:24:06] >> mysql_store_result( Connection handle: 1 )

[16:24:06] CMySQLHandler::StoreResult() - Result was stored.

[16:24:06] >> mysql_fetch_row_format( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchRow() - Return: 0|0|16|0|0|0|0|0|0|0|0|0|0|0|0||46|127|-64|2|315

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("score") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("money") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("level") - 16

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("vip") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("kma") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("rank") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("kills") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("deaths") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("muted") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("jailed") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("frozen") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("mutedtimes") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("jailedtimes") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("frozentimes") - 0

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("logins") - 46

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("posx") - 127

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("posy") - -64

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("posz") - 2

[16:24:06] >> mysql_fetch_field_row( Connection handle: 1 )

[16:24:06] CMySQLHandler::FetchField("posa") - 315

[16:24:06] >> mysql_fetch_row_format( Connection handle: 1 )

[16:24:06] >> mysql_free_result( Connection handle: 1 )

[16:24:06] CMySQLHandler::FreeResult() - Result was successfully free'd.

[16:24:06] >> mysql_free_result( Connection handle: 1 )

[16:24:06] CMySQLHandler::FreeResult() - The result is already empty.
Reply
#9

NVM, I will contact you when I'm home and will fix it over teamviewer if you like.
Reply
#10

That would be extremely helpful, thank you very much. A moderator/Beta tester can lock this now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)