INSERTing variable names instead of variable value

Results 1 to 3 of 3

Thread: INSERTing variable names instead of variable value

  1. #1
    DavidB Guest

    Default INSERTing variable names instead of variable value

    I am gathering information for a database using a form and then passing the information to an ASP page using the post method. The ASP page collects the form data in variables and uses an SQL statement to insert the info into an ACCESS database. However, the data inserted is the name of the variable rather than its value. When I Response.Write the variables following the INSERT statement, the information is printed correctly. I have a feeling that there is something wrong with my syntax, but I am pulling my hair out trying to find it. (I&#039m going on two full days attempting to correct this single problem!) Below is an excerpt from my ASP page. Let me know if you can help.<BR><BR>&#060;%<BR><BR>&#039Declare variables.<BR><BR>Dim strFirstName<BR>Dim strLastName<BR>Dim strAddress<BR>Dim strCity<BR>Dim strState<BR>Dim strZip<BR>Dim strHPhone<BR>Dim strWPhone<BR>Dim strEmail<BR>Dim strEmployer<BR>Dim strOccupation<BR>Dim strAmount<BR>Dim strCheck<BR>Dim strComments<BR><BR>Dim SQLINSERT<BR>Dim objConnUpdate<BR><BR>&#039Grab variables from the Form.<BR><BR>strFirstName=Request.Form("firstName" )<BR>strLastName=Request.Form("lastName")<BR>strAd dress=Request.Form("address")<BR>strCity=Request.F orm("city")<BR>strState=Request.Form("state")<BR>s trZip=Request.Form("zip")<BR>strHPhone=Request.For m("phone1")<BR>strWPhone=Request.Form("phone2")<BR >strEmail=Request.Form("email")<BR>strEmployer=Req uest.Form("employer")<BR>strOccupation=Request.For m("occupation")<BR>strAmount=Request.Form("amount" )<BR>strCheck=Request.Form("check")<BR>strComments =Request.Form("comments")<BR><BR>&#039Create the INSERT statement for a new contact.<BR> <BR>SQLINSERT="INSERT INTO contacts (firstName, lastName, address1, city, state, zip) VALUES (&#039strFirstName&#039, &#039strLastName&#039, &#039strAddress&#039, &#039strCity&#039, &#039strState&#039, &#039strZip&#039)"<BR><BR>set objConnUpdate = Server.CreateObject("ADODB.Connection")<BR>objConn "linton2000"<BR>objConnUpdate.execute(SQLINSERT)<B R>objConnUpdate.close<BR><BR>%&#062;

  2. #2
    Ed Guest

    Default RE: INSERTing variable names instead of variable v

    Since you are wanting to insert the values of the variables, you must create your SQL string like:<BR><BR>SQLINSERT = "INSERT INTO contacts (firstname, lastname, ...) VALUES(&#039" & strFirstName & "&#039,&#039" & strLastName & "&#039,&#039" & ... & "&#039)"<BR><BR>This will insert the values of the variables into the SQL string.

  3. #3
    DavidB Guest

    Default RE: INSERTing variable names instead of variable v

    Thanks Ed. What an easy fix.

Posting Permissions

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