Professional Web Applications Themes

What is wrong with this insert statement? - Coldfusion Database Access

Here is the code: (I'll put the error below) <cfquery datasource="hubclub"> INSERT INTO Customers, Orders ( Customers.FirstName, Customers.LastName, Customers.Address, Customers.City, "Customers.State", Customers.PostalCode, Customers.EmailAddress, Customers.SecondaryEmailAddress, Customers.SoldBy, Orders.BillingName, Orders.BillingAddress, Orders.BillingCity, Orders.BillingState, Orders.BillingPostalCode, Orders.BillingPhoneNumber) VALUES ( <cfif IsDefined("FORM.FirstName") AND #FORM.FirstName# NEQ ""> '#FORM.FirstName#' <cfelse> NULL </cfif> , <cfif IsDefined("FORM.LastName") AND #FORM.LastName# NEQ ""> '#FORM.LastName#' <cfelse> NULL </cfif> , <cfif IsDefined("FORM.Address") AND #FORM.Address# NEQ ""> '#FORM.Address#' <cfelse> NULL </cfif> , <cfif IsDefined("FORM.City") AND #FORM.City# NEQ ""> '#FORM.City#' <cfelse> NULL </cfif> , <cfif IsDefined("FORM.State") AND #FORM.State# NEQ ""> '#FORM.State#' <cfelse> NULL </cfif> , <cfif IsDefined("FORM.PostalCode") AND #FORM.PostalCode# NEQ ""> '#FORM.PostalCode#' <cfelse> NULL </cfif> , <cfif ...

  1. #1

    Default What is wrong with this insert statement?

    Here is the code: (I'll put the error below)

    <cfquery datasource="hubclub">
    INSERT INTO Customers, Orders (
    Customers.FirstName,
    Customers.LastName,
    Customers.Address,
    Customers.City,
    "Customers.State",
    Customers.PostalCode,
    Customers.EmailAddress,
    Customers.SecondaryEmailAddress,
    Customers.SoldBy,
    Orders.BillingName,
    Orders.BillingAddress,
    Orders.BillingCity,
    Orders.BillingState,
    Orders.BillingPostalCode,
    Orders.BillingPhoneNumber) VALUES (
    <cfif IsDefined("FORM.FirstName") AND #FORM.FirstName# NEQ "">
    '#FORM.FirstName#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.LastName") AND #FORM.LastName# NEQ "">
    '#FORM.LastName#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.Address") AND #FORM.Address# NEQ "">
    '#FORM.Address#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.City") AND #FORM.City# NEQ "">
    '#FORM.City#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.State") AND #FORM.State# NEQ "">
    '#FORM.State#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.PostalCode") AND #FORM.PostalCode# NEQ "">
    '#FORM.PostalCode#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.EmailAddress") AND #FORM.EmailAddress# NEQ "">
    '#FORM.EmailAddress#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.SecondaryEmailAddress") AND
    #FORM.SecondaryEmailAddress# NEQ "">
    '#FORM.SecondaryEmailAddress#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.SoldBy") AND #FORM.SoldBy# NEQ "">
    #FORM.SoldBy#
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.BillingName") AND #FORM.BillingName# NEQ "">
    '#FORM.BillingName#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.BillingAddress") AND #FORM.BillingAddress# NEQ "">
    '#FORM.BillingAddress#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.BillingCity") AND #FORM.BillingCity# NEQ "">
    '#FORM.BillingCity#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.BillingState") AND #FORM.BillingState# NEQ "">
    '#FORM.BillingState#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.BillingPostalCode") AND #FORM.BillingPostalCode# NEQ
    "">
    '#FORM.BillingPostalCode#'
    <cfelse>
    NULL
    </cfif>
    ,
    <cfif IsDefined("FORM.BillingPhoneNumber") AND #FORM.BillingPhoneNumber# NEQ
    "">
    '#FORM.BillingPhoneNumber#'
    <cfelse>
    NULL
    </cfif>
    )
    </cfquery>
    <cflocation url="purchase.cfm?E=#form.EmailAddress#">
    </cfif>

    Error Message:
    Error Executing Database Query.
    Syntax error in INSERT INTO statement.

    The error occurred in C:\CFusionMX7\wwwroot\hub\join\index.cfm: line 108

    106 : <cfelse>
    107 : NULL
    108 : </cfif>
    109 : )
    110 : </cfquery>




    --------------------------------------------------------------------------------

    SQL INSERT INTO Customers, Orders ( Customers.FirstName,
    Customers.LastName, Customers.Address, Customers.City, "Customers.State",
    Customers.PostalCode, Customers.EmailAddress, Customers.SecondaryEmailAddress,
    Customers.SoldBy, Orders.BillingName, Orders.BillingAddress,
    Orders.BillingCity, Orders.BillingState, Orders.BillingPostalCode,
    Orders.BillingPhoneNumber) VALUES ( *values are here i just took them out it
    has my personal info.* )
    DATASOURCE hubclub
    VENDORERRORCODE 3092
    SQLSTATE &nbsp;

    Please try the following:
    Check the ColdFusion doentation to verify that you are using the correct
    syntax.
    Search the Knowledge Base to find a solution to your problem.


    Browser Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR
    1.1.4322)
    Remote Address 127.0.0.1
    Referrer [url]http://localhost:8500/hub/join/index.cfm[/url]
    Date/Time 13-May-05 03:32 AM



    chill84 Guest

  2. #2

    Default Re: What is wrong with this insert statement?

    As far as I know, the SQL Insert will add one row to one table. The code
    typically looks like INSERT INTO yourTable. Your code does not look like
    that. Maybe you want to 2 related INSERTs. A SQL Stored Procedure or
    CFtransaction may be the way to go. hth

    -brian

    "chill84" <webforumsusermacromedia.com> wrote in message
    news:d61pb4$sp5$1forums.macromedia.com...
    > Here is the code: (I'll put the error below)
    >
    > <cfquery datasource="hubclub">
    > INSERT INTO Customers, Orders (
    > Customers.FirstName,
    > Customers.LastName,
    > Customers.Address,
    > Customers.City,
    > "Customers.State",
    > Customers.PostalCode,
    > Customers.EmailAddress,
    > Customers.SecondaryEmailAddress,
    > Customers.SoldBy,
    > Orders.BillingName,
    > Orders.BillingAddress,
    > Orders.BillingCity,
    > Orders.BillingState,
    > Orders.BillingPostalCode,
    > Orders.BillingPhoneNumber) VALUES (
    > <cfif IsDefined("FORM.FirstName") AND #FORM.FirstName# NEQ "">
    > '#FORM.FirstName#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.LastName") AND #FORM.LastName# NEQ "">
    > '#FORM.LastName#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.Address") AND #FORM.Address# NEQ "">
    > '#FORM.Address#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.City") AND #FORM.City# NEQ "">
    > '#FORM.City#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.State") AND #FORM.State# NEQ "">
    > '#FORM.State#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.PostalCode") AND #FORM.PostalCode# NEQ "">
    > '#FORM.PostalCode#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.EmailAddress") AND #FORM.EmailAddress# NEQ "">
    > '#FORM.EmailAddress#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.SecondaryEmailAddress") AND
    > #FORM.SecondaryEmailAddress# NEQ "">
    > '#FORM.SecondaryEmailAddress#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.SoldBy") AND #FORM.SoldBy# NEQ "">
    > #FORM.SoldBy#
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.BillingName") AND #FORM.BillingName# NEQ "">
    > '#FORM.BillingName#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.BillingAddress") AND #FORM.BillingAddress# NEQ
    "">
    > '#FORM.BillingAddress#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.BillingCity") AND #FORM.BillingCity# NEQ "">
    > '#FORM.BillingCity#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.BillingState") AND #FORM.BillingState# NEQ "">
    > '#FORM.BillingState#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.BillingPostalCode") AND #FORM.BillingPostalCode#
    NEQ
    > "">
    > '#FORM.BillingPostalCode#'
    > <cfelse>
    > NULL
    > </cfif>
    > ,
    > <cfif IsDefined("FORM.BillingPhoneNumber") AND
    #FORM.BillingPhoneNumber# NEQ
    > "">
    > '#FORM.BillingPhoneNumber#'
    > <cfelse>
    > NULL
    > </cfif>
    > )
    > </cfquery>
    > <cflocation url="purchase.cfm?E=#form.EmailAddress#">
    > </cfif>
    >
    > Error Message:
    > Error Executing Database Query.
    > Syntax error in INSERT INTO statement.
    >
    > The error occurred in C:\CFusionMX7\wwwroot\hub\join\index.cfm: line 108
    >
    > 106 : <cfelse>
    > 107 : NULL
    > 108 : </cfif>
    > 109 : )
    > 110 : </cfquery>
    >
    >
    >
    >
    > --------------------------------------------------------------------------
    ------
    >
    > SQL INSERT INTO Customers, Orders ( Customers.FirstName,
    > Customers.LastName, Customers.Address, Customers.City, "Customers.State",
    > Customers.PostalCode, Customers.EmailAddress,
    Customers.SecondaryEmailAddress,
    > Customers.SoldBy, Orders.BillingName, Orders.BillingAddress,
    > Orders.BillingCity, Orders.BillingState, Orders.BillingPostalCode,
    > Orders.BillingPhoneNumber) VALUES ( *values are here i just took them out
    it
    > has my personal info.* )
    > DATASOURCE hubclub
    > VENDORERRORCODE 3092
    > SQLSTATE &nbsp;
    >
    > Please try the following:
    > Check the ColdFusion doentation to verify that you are using the
    correct
    > syntax.
    > Search the Knowledge Base to find a solution to your problem.
    >
    >
    > Browser Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET
    CLR
    > 1.1.4322)
    > Remote Address 127.0.0.1
    > Referrer [url]http://localhost:8500/hub/join/index.cfm[/url]
    > Date/Time 13-May-05 03:32 AM
    >
    >
    >

    Brian Hogue Guest

Similar Threads

  1. Question Insert from ASP to SQL using recordset data as values in insert statement
    By JasonM in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: June 13th, 05:54 PM
  2. Help! What's wrong with my QUERY statement??
    By RuBot in forum Coldfusion Database Access
    Replies: 5
    Last Post: August 13th, 09:05 AM
  3. Replies: 3
    Last Post: September 30th, 09:24 PM
  4. Replies: 4
    Last Post: September 16th, 04:54 PM
  5. Insert Statement help
    By ksbrace in forum Microsoft SQL / MS SQL Server
    Replies: 0
    Last Post: June 30th, 02:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139