Page 1 of 1

PHP MSSQL Money Datatype crash

Posted: Mon Jun 11, 2007 9:16 am
by ghadacr
In MSSQL database i have a Money datatype. When i run the a bit of code to insert some data into the database i get the following error:
Disallowed implicit conversion from data type varchar to data type money, table 'PBSalesRes.dbo.Flights', column 'AdultCost'. Use the CONVERT function to run this query.
Know i have adapted the code to convert but that does not seem to work...

I did have a problem similiar to this with the date, i resolved it using this bit of code:

Code: Select all

$csds = str_replace("/","-",$canceldate);
$newcancel = date ("d M Y", strtotime ($csds));
if any one is got some code that can help with the MONEY problem will be much apperciated...

Posted: Mon Jun 11, 2007 11:28 am
by RobertGonzalez
You are probably going to have to take it as a varchar in the procedure, then in the procedure convert to money type as there is not direct relationship to money in PHP.

Posted: Mon Jun 11, 2007 11:46 am
by ghadacr
Thanks for the suggestion, for this query its not in a stored procedure.

Query:

Code: Select all

$query ="INSERT INTO Flights (CarrierID, OutBoundFlightNumber, InBoundFlightNumber, GroupName, AdultCost, ChildCost, FlightFrom, FlightTo, OutBoundDate, InBoundDate, OutBoundTime, InBoundTime, NumberOfSeatsLeft, Notes, ResortID) 
VALUES ('$_GET[CarrierID]', '$_GET[outboundflightno]', '$_GET[returnflightno]', '$_GET[groupname]', '$_GET[cost_adult]', '$_GET[cost_child]', '$_GET[from]', '$_GET[to]', '$newdate', '$newdates', '$_GET[outbound_time]', '$_GET[return_time]', '$_GET[no_seats]', '$Notes', '$_GET[cat]')";

Code: Select all

The ones concerned are AdultCost, ChildCost ,'$_GET[cost_adult]','$_GET[cost_child]'
When i try to edit this query to convert to money it does not work....Hmmm

Posted: Mon Jun 11, 2007 11:59 am
by RobertGonzalez
Can you use a convert function at the query level? If not, can you write a procedure to handle this?