PHP MSSQL Money Datatype crash

Discussion in 'PHP' started by ghadacr, Jun 11, 2007.

  1. #1
    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...
     
    ghadacr, Jun 11, 2007 IP
  2. mad4

    mad4 Peon

    Messages:
    6,986
    Likes Received:
    493
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Sounds like you are adding something to the database which isn't compatible with the money field.

    What is the value you are adding?
     
    mad4, Jun 11, 2007 IP
  3. ghadacr

    ghadacr Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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..
     
    ghadacr, Jun 11, 2007 IP
  4. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #4
    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...
     
    TwistMyArm, Jun 11, 2007 IP
  5. ghadacr

    ghadacr Peon

    Messages:
    30
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    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:
     
    ghadacr, Jun 11, 2007 IP
  6. TwistMyArm

    TwistMyArm Peon

    Messages:
    931
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    TwistMyArm, Jun 11, 2007 IP