SA-MP Forums Archive
MySQL Query not inserting data into the table - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL Query not inserting data into the table (/showthread.php?tid=386260)



MySQL Query not inserting data into the table - NewerthRoleplay - 19.10.2012

Hey I am using mysql on my server with my script on and whenever I use the command: createhouse I get the message saying that it has been inputted into the the database, however when I enter the table using phpmyadmin it clearly has not here is the code to create the table and insert the data:

pawn Код:
mysql_query("CREATE TABLE IF NOT EXISTS houseinfo(id INT AUTO_INCREMENT PRIMARY KEY, owner VARCHAR(32), owned BOOLEAN, interior INT, EnterX VARCHAR(1024), EnterY VARCHAR(1024), EnterZ VARCHAR(1024), price INT, level INT)", dbconnect);
    new sql[128], owner[128], owned;
    owner = "For Sale";
    owned = 0;
    format(sql, sizeof(sql), "INSERT INTO `houseinfo` (id, owner, owned, interior, EnterX, EnterY, EnterZ, price, level) VALUES (NULL, %s, %i, %i, %f, %f, %f, %i, %i)",owner, owned, houseint, x, y, z, housecost, houselevel);
    mysql_query(sql, dbconnect);



Re: MySQL Query not inserting data into the table - Vince - 19.10.2012

EnterX/Y/Z should be float, not varchar. Varchar is a string type.


Re: MySQL Query not inserting data into the table - ReneG - 19.10.2012

You don't need to insert values into auto increment fields since they're automatically filled with an increment (hence 'auto increment') Also, when all else fails, enable mysql_debug and see what prints out in mysql_log.txt.


Re: MySQL Query not inserting data into the table - NewerthRoleplay - 19.10.2012

Tried removing the auto increment field (Should have said I already tried that) and I changed the rows in the table for the co-ordinates to float's. Still makes no difference :S Here is what the code is currently
pawn Код:
mysql_query("CREATE TABLE IF NOT EXISTS houseinfo(id INT AUTO_INCREMENT PRIMARY KEY, owner VARCHAR(32), owned BOOLEAN, interior INT, EnterX FLOAT, EnterY FLOAT, EnterZ FLOAT, price INT, level INT)", dbconnect);
    new sql[128], owner[128], owned;
    owner = "For Sale";
    owned = 0;
    format(sql, sizeof(sql), "INSERT INTO `houseinfo` (owner, owned, interior, EnterX, EnterY, EnterZ, price, level) VALUES (%s, %i, %i, %f, %f, %f, %i, %i)",owner, owned, houseint, x, y, z, housecost, houselevel);
    mysql_query(sql, dbconnect);



Re: MySQL Query not inserting data into the table - ReneG - 19.10.2012

Maybe it's because you're trying to put an integer into a boolean field? I'm not too sure. Input these queries in the SQL tab in phpmyadmin.


Re: MySQL Query not inserting data into the table - NewerthRoleplay - 20.10.2012

Quote:
Originally Posted by VincentDunn
Посмотреть сообщение
Maybe it's because you're trying to put an integer into a boolean field? I'm not too sure. Input these queries in the SQL tab in phpmyadmin.
It worked perfectly with the SQL tab :S