Jump to content


Photo

PHP and MSSQL


  • Please log in to reply
4 replies to this topic

#1 everstudios

everstudios
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 28 February 2006 - 10:17 PM

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

$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')");

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?

#2 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 28 February 2006 - 10:56 PM

If your number is 1234.5678

This:

$total = number_format($total, 2, '.', '');

Will produce this: 1,234.56

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

#3 everstudios

everstudios
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 01 March 2006 - 12:34 AM

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

#4 Caesar

Caesar
  • Members
  • PipPipPip
  • Advanced Member
  • 1,025 posts

Posted 01 March 2006 - 03:11 AM

Benn a while since I dealth with currency...or MSSQL, for that matter.

Try this:
<?php

$money = '32456.666';

$momoney = number_format($money, 2, '.', '');

$total = money_format($momoney, 2);

echo $total;

?>  

PHP Ninja

#5 everstudios

everstudios
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 01 March 2006 - 06:06 PM

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?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users