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. HTML: 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: $csds = str_replace("/","-",$canceldate); $newcancel = date ("d M Y", strtotime ($csds)); PHP: if any one is got some code that can help with the MONEY problem will be much apperciated...
Sounds like you are adding something to the database which isn't compatible with the money field. What is the value you are adding?
It's just integer number's such as 34 and 546. But the databas thinks its a varchar, so i need a to convert the incoming value to a MONEY type. I'm not sure how to do that..
You aren't, by any chance, wrapping quotes (either double or single) around those integers, are you? It would help if you actually show us the query that you're using...
Here is the query: $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]','$_GET[outbound_date]','$_GET[return_date]','$_GET[outbound_time]','$_GET[return_time]','$_GET[no_seats]','$_GET[notes]','$_GET[cat]')"; PHP: The ones concered are: $_GET[cost_child] $_GET[cost_adult] PHP:
Yeah... not knowing MSSQL specifically, from the error I would guess it's because of the single quotes around the two money fields (cost_adult and cost_child). I'd try: $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]','$_GET[outbound_date]','$_GET[return_date]','$_GET[outbound_time]','$_GET[return_time]','$_GET[no_seats]','$_GET[notes]','$_GET[cat]')" Code (markup): instead.