PHP MSSQL Money Datatype crash

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

PHP MSSQL Money Datatype crash

Post 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...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Can you use a convert function at the query level? If not, can you write a procedure to handle this?
Post Reply