www.webdeveloper.com
Results 1 to 3 of 3

Thread: SQL update statement using form data as field name

  1. #1
    Join Date
    Jul 2005
    Posts
    55

    SQL update statement using form data as field name

    im trying to write a SQL statement that will update a column in my access database based on a selection chosen from a form. the select box in the form is called STEP. the values range from A_DATE to U_DATE. there also two textboxes, one called "CONNUM" and one called "ENTDATE". the database has columns called "CON_NUM" and others, ranging from A_DATE to U_DATE. an example: the user chooses STEP = A_DATE, then enters 3002 in CONNUM, and 12/23/2004 in ENTDATE. when they submit, the database should update column A_DATE with 12/23/2004 WHERE CON_NUM=3002. im kinda familar with SQL but just can not get this to work. here's my code so far:

    Code:
    putCONNUM=request.form("CONNUM")
    putSTEP=request.form("STEP")
    putENTDATE=request.form("ENTDATE")
    
    sql="UPDATE CONTRACTS SET '"& putSTEP &"' = '" & putENTDATE & "' WHERE CON_NUM = '"& putCONNUM & "'"
    if i replace '"& putSTEP &"' with A_DATE, it works. however, if i did it that way, i'd have to write IF and SQL statements for each STEP from A_DATE to U_DATE. any ideas?

    thanks in advance for the help.

  2. #2
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    when you echo it, the statement looks correct? do you need the single quotes around the field in Access??

  3. #3
    Join Date
    Jul 2005
    Posts
    55
    you're exactly right, it works without the single quotes around the field :

    Code:
    sql="UPDATE CONTRACTS SET "& putSTEP &" = '" & putENTDATE & "' WHERE CON_NUM = '"& putCONNUM & "'"
    thanks for the help!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles