Jump to content

Archived

This topic is now archived and is closed to further replies.

everstudios

PHP and MSSQL

Recommended Posts

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?

Share this post


Link to post
Share on other sites
If your number is 1234.5678

This:

[code]$total = number_format($total, 2, '.', '');[/code]

Will produce this: 1,234.56

Hope I read your question right, and hope that helps.

Share this post


Link to post
Share on other sites
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 578

So 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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.