everstudios Posted February 28, 2006 Share Posted February 28, 2006 Hello Everyone,I'm having trouble Inserting a variable into a 'money' feild.i am passing a variable allong called $total.WHen it comes time to insert into my database, i use [code]$result = mssql_query(" INSERT INTO $Table_Activity (SEQN,ID,ACTIVITY_TYPE, Product_code,TRANSACTION_DATE,DESCRIPTION,NOTE,UF_1,UF_2,EFFECTIVE_DATE,THRU_DATE,AMOUNT,ACTION_CODES) VALUES ('$seqn','$id','ADS','$newarray[$insertcount], WEB','$inserttoday','$category','$class_city. $class_ad','$class_city','$cardtype','$inserttomorrow','$insertnextmonth','$total','$words')");[/code]when i do that, i get an error because the AMOUNT feild is a Money Type and my variable is not. My Question is how do i convert my $total variable into something that the money feild will accept. I tried reading up on the CONVERT funtion for SQL, but not getting far wtih it. Is there an easy way to do this? Quote Link to comment https://forums.phpfreaks.com/topic/3781-php-and-mssql/ Share on other sites More sharing options...
Caesar Posted February 28, 2006 Share Posted February 28, 2006 If your number is 1234.5678This:[code]$total = number_format($total, 2, '.', '');[/code]Will produce this: 1,234.56Hope I read your question right, and hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/3781-php-and-mssql/#findComment-13144 Share on other sites More sharing options...
everstudios Posted March 1, 2006 Author Share Posted March 1, 2006 Thanks for replying, the code you gave me converted the number into a currency but the SQL insert code is still not accepting it for a Money field. Do you have any other ideas. The error i am getting is:Warning: mssql_query(): message: Disallowed implicit conversion from data type varchar to data type money, table 'camft.dbo.Activity', column 'AMOUNT'. Use the CONVERT function to run this query. (severity 16) in C:\Inetpub\vhosts\camftads.com\httpdocs\mssql\7.php on line 578So i need to use the convert funtion in SQL, but i don;t know how to use that in the code i gave above. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/3781-php-and-mssql/#findComment-13168 Share on other sites More sharing options...
Caesar Posted March 1, 2006 Share Posted March 1, 2006 Benn a while since I dealth with currency...or MSSQL, for that matter.Try this:[code]<?php$money = '32456.666';$momoney = number_format($money, 2, '.', '');$total = money_format($momoney, 2);echo $total;?> [/code] Quote Link to comment https://forums.phpfreaks.com/topic/3781-php-and-mssql/#findComment-13197 Share on other sites More sharing options...
everstudios Posted March 1, 2006 Author Share Posted March 1, 2006 Thanks for replying.That code says that money_format is an undefined funtion. is that suppose to be number?I just read up on money format and it doesnt not work with windows servers. I am on a windows platform. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/3781-php-and-mssql/#findComment-13353 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.