Click to See Complete Forum and Search --> : very strange problem with insert command
pelegk1
12-15-2003, 08:26 AM
i am working php+mySql
i am trying to do a simple insert command :
$query2="INSERT INTO tblPrint (OrderNum,PrinterNum,DateTimeVal) Values('$order_num','$radio','$tmpDateTimeVal')";
when i havethis values :
$order_num=313.517;
$radio=1;
$tmpDateTimeVal=date("Y-m-d H:i:s");
when i check the mysql i see that the order_num value
is for some reason 3.517 ?!?!?!?!?!
why is that?any idea????
the more intresting if i do the same line with the same values it tels me its a duplicate key!!!!!!
but if i chek it from php with a select it tells m that that vakue dosent exist!!!!!!!!
help dont know what else to do!
What is the field type of the order_num field in your table?
pelegk1
12-15-2003, 10:23 AM
varchar 8
by the way whats the diffrdence between var and varchar?
Did you mean CHAR & VARCHAR ... I think it's mainly to do with how MySQL stores the strings 'under-the-bonnet' ... with CHAR being stored as fixed-length and VARCHAR stored according to the actual data's length.
Back to your problem, it sort of looks like MySQL is assuming that it is a numeric value in the first place or there's some kind of conversion going on as the data is being stored.
Try enforcing MSQL to view the data as a string ...
$query2="INSERT INTO tblPrint (OrderNum,PrinterNum,DateTimeVal) Values(CONCAT('', '$order_num'),'$radio','$tmpDateTimeVal')";
... that might work.
pelegk1
12-15-2003, 11:16 AM
beacuse
when i did :
$query2="INSERT INTO tblPrint (OrderNum,PrinterNum,DateTimeVal) Values('111.1234','$radio','$tmpDateTimeVal')";
it worked ok!
pelegk1
12-15-2003, 11:18 AM
hope it helps
but still isnt varchar is all of chars? or i miss understand somehing?
whats the diffrence with char
My 'hack' might not work ... I haven't tested it ... but a hunt through the MySQL manual might yield a straightforward function to 'cast' a number as a string.
Difference between CHAR and VARCHAR (rough idea only).
Suppose you have two fields:
CHAR(10) charname
VARCHAR(10) varname
and you store the name Paul, with only 4 characters, in both. Then VARCHAR will only store the four characters, so is a little more space-efficient that CHAR which stores the 4 characters but still leaves room for the other 6.
But VARCHAR costs more time as MySQL has to work out how to optimise the storage.
Actually, VARCHAR will record the 4 characters, plus one byte to record the length: http://www.mysql.com/doc/en/CHAR.html
Thanks, pyro, for correcting me.
It was really quite minor - your descriptoin was good. :)
pelegk1
12-16-2003, 12:44 AM
i changed the varchar to size 11
it at last put the data but when i do :
select * from tblprint where ordernum like '%313.1729%'
bu i get 0 records!!!why??????
Hallo,
pelegk1 posted this thread at phpbuilder too. He declared the $order_num variable on a wrong way (as integer)
All his request sounds like that PHP do strange things. I hope that these things happens only to him....
pelegk1
12-16-2003, 02:36 AM
and i didnt decalre it as $order_num int
but as varchar(8)
and i have an example that it works but i ont see the diffrence!