[MySQL] Can't enter float into database.
#1

Hi there,
I am having trouble with inserting floats into my MySQL database.

In my database, my table has 3 fields called EntX, EntY, EntZ. Their types are all floats, and they don't have a length.

This is my code:
pawn Код:
CreateBusiness(1, "A Test", 20000, 0.0000, 0.0000, 4.0000); // Create Bizz.
//The Actual function.
function CreateBusiness(bid, Bizzname[], price, Float:EnterX, Float:EnterY, Float:EnterZ)
{
    if(bid > MAX_HOUSES) return 0;
    format(str, sizeof(str), "SELECT * FROM `bizzinfo` WHERE `bid` = %d", bid);
    mysql_query(str);
    mysql_store_result();
    if(mysql_num_rows() > 0) return 0;
    format(str, sizeof(str), "INSERT INTO `bizzinfo` (bid, BizzName, Owner, Price, PayAmount, EntX, EntY, EntZ) VALUES (%d, '%s', 'For Sale', %d, 5000, %f, %f, %f)", bid, Bizzname, price, EnterX, EnterY, EnterZ);
    mysql_query(str);
    printf("[BIZZ]: Business ID: %d was added to the database.", bid);
    mysql_free_result();
    return 1;
}
And this is what I get when I query it into the database.


This is my MySQL Log.
Код:
[Thu Sep 16 21:06:16 2010] -------------------------
[Thu Sep 16 21:06:16 2010]      Logging Started
[Thu Sep 16 21:06:16 2010] -------------------------
[Thu Sep 16 21:06:16 2010] Connected (0) to root @ localhost via TCP/IP.
[Thu Sep 16 21:06:16 2010] MySQL Version 5.1.36-community-log.
[Thu Sep 16 21:06:16 2010] Function: mysql_query executed: "SELECT * FROM `bizzinfo` WHERE `bid` = 1" with result: "0".
[Thu Sep 16 21:06:16 2010] Function: mysql_store_result executed with result: "1"
[Thu Sep 16 21:06:16 2010] Function: mysql_num_rows executed with result: "".
[Thu Sep 16 21:06:16 2010] Function: mysql_query executed: "INSERT INTO `bizzinfo` (bid, BizzName, Owner, Price, PayAmount, EntX, EntY, EntZ) VALUES (1, 'A Test', 'For Sale', 20000, 5000, 0.000000, 0.000000, 4.000000)" with result: "0".
[Thu Sep 16 21:06:16 2010] Function: mysql_free_result executed.
[Thu Sep 16 21:06:16 2010] Function: mysql_query executed: "SELECT * FROM `bizzinfo`" with result: "0".
[Thu Sep 16 21:06:16 2010] Function: mysql_store_result executed with result: "1"
[Thu Sep 16 21:06:16 2010] Function: mysql_num_rows executed with result: "".
[Thu Sep 16 21:06:16 2010] Function: mysql_fetch_row executed with result: "1|A Test|For Sale|20000|5000|0|0|4".
[Thu Sep 16 21:06:16 2010] Function: mysql_free_result executed.
Sigh,
Can anyone help please.
Reply
#2

Bump...if I could get an answer please.
Reply
#3

EntX, EntY and EntZ all need to be varchars (pretty sure).
Reply
#4

With lenght you mean numbers after the point?

If that's true, you need varchars
Reply
#5

You put the database to receive float values? I Guess no!!
Reply
#6

'EntX, EntY, EntZ' needs to be 'float' as a table, and I am sure about that. I guess you didn't do that.
Reply
#7

Quote:
Originally Posted by [HiC]TheKiller
Посмотреть сообщение
EntX, EntY and EntZ all need to be varchars (pretty sure).
I'll try that, but I doubt it will work, as this is going to be a decimal number.. (i.e 0.0).

Quote:
Originally Posted by dirkblok
Посмотреть сообщение
With lenght you mean numbers after the point?



If that's true, you need varchars
No, I can't query any float decimal number, so yes...I guess with #'s with decimals at the end.

Quote:
Originally Posted by xyu3xx
Посмотреть сообщение
You put the database to receive float values? I Guess no!!
It is float, I'm not that stupid.

Quote:
Originally Posted by playbox12
Посмотреть сообщение
'EntX, EntY, EntZ' needs to be 'float' as a table, and I am sure about that. I guess you didn't do that.
Fields EntX, EntY, EntZ are floats.
Reply
#8

Bump again...I still can't figure why it can't input the floats.. Just to be clear:
The field types are FLOATS.

Edit: heres my table if anyone wants to make sure.
Код:
CREATE TABLE IF NOT EXISTS `bizzinfo` (
  `bid` int(5) NOT NULL,
  `BizzName` varchar(24) NOT NULL,
  `Owner` varchar(24) NOT NULL,
  `Price` int(12) NOT NULL,
  `PayAmount` int(12) NOT NULL,
  `EntX` float NOT NULL,
  `EntY` float NOT NULL,
  `EntZ` float NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Reply
#9

change entx, enty, entz to varchar then try.
Reply
#10

Everything looks right to me, if there are no decimal places, you won't see them.
Just try to set for example EntX to something like 0.1234 and you should see it like that in phpMyAdmin.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)