INSERT INTO using HTML forms

Ask a Question related to ASP, Design and Development.

  1. #1

    Default INSERT INTO using HTML forms

    I'm having issues witht the code I'm writing. I've dealt with SQL before,
    although only for extracting data, not adding it to the database. I've been
    intensively learning ASP/ADO over the past week or so. I have a HTML form
    that posts data to the following ASP file:

    <HTML>
    <HEAD>
    <TITLE>Sight Bites</TITLE>
    </HEAD>

    <BODY>

    <%
    set conn = Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open(Server.Mappath("data/guest.mdb"))

    stmt = "INSERT INTO Guest (Name, Location, Date, Email, Website, Comment)"
    stmt = stmt & "VALUES ('" & Request.Form("Name") & "', '" &
    Request.Form("Location") & "', '" & Date & "', '"
    stmt = stmt & Request.Form("Email") & "', '" & Request.Form("Website") &
    "', '" & Request.Form("Comment") & "')"


    on error resume next
    conn.Execute stmt, recaffected
    if err<>0 then
    response.write "VBScript Errors Occured:" & "<P>"
    response.write "Error Number=" & err.number & "<P>"
    response.write "Error Descr.=" & err.description & "<P>"
    response.write "Help Context=" & err.helpcontext & "<P>"
    response.write "Help Path=" & err.helppath & "<P>"
    response.write "Native Error=" & err.nativeerror & "<P>"
    response.write "Source=" & err.source & "<P>"
    response.write "SQLState=" & err.sqlstate & "<P>"
    else
    Response.Write("Updated!")
    end if
    conn.Close
    %>

    <HR/>
    <CENTER><H5><I>2003 Ian Griffiths</I></H5></CENTER>
    </BODY>
    </HTML>

    I've run this using IIS, but I always seem to get a systax error in my
    INSERT statement, but I can't spot one. Anyone got any pointers?

    Cheers,

    Ian Griffiths.


    Ian Griffiths Guest

  2. Similar Questions and Discussions

    1. Forms Insert Image Field?
      I want to create a form for a client with the standard form elements that can be filled out and saved with Reader. This seems to be the case with...
    2. Open to insert html?
      I use Contribute to udpate and chage our web page, but I need to add banners and I can't find anything in the help section about opening up the ...
    3. I need a View, Insert, Update, Delete paradigm for usingflash forms
      Flash forms are the greatest. But I'm struggling with a usable paradigm for handling all database functions with them. Most notably, since I can't...
    4. How to insert html in contribute 3
      I am trying to insert a counter on my webpage but I can't figure out how to insert the html text. I have never worked with html before and can't...
    5. Insert HTML?
      Is there any way to insert your own html object in Fireworks? Where it shows a box that just says HTML and you double click it to edit a code or...
  3. #2

    Default Re: INSERT INTO using HTML forms

    On Sun, 26 Oct 2003 13:09:41 +0000 (UTC), "Ian Griffiths"
    <Ian_Excelle@btopenworld.com> wrote:

    >
    > stmt = "INSERT INTO Guest (Name, Location, Date, Email, Website, Comment)"
    > stmt = stmt & "VALUES ('" & Request.Form("Name") & "', '" &
    >Request.Form("Location") & "', '" & Date & "', '"
    > stmt = stmt & Request.Form("Email") & "', '" & Request.Form("Website") &
    >"', '" & Request.Form("Comment") & "')"
    >
    >
    >
    >I've run this using IIS, but I always seem to get a systax error in my
    >INSERT statement, but I can't spot one. Anyone got any pointers?
    >
    Check a couple things...

    First off, use Response.Write stmt just before issuing the statement
    to SQL. This might show you more.

    Next look at the syntax for delimiters on dates using Access
    databases. It requires "#" marks for delimiters.

    Lastly, take a look at the comments. If they contain single quotes
    anywhere in them, this will make the statement fail. For any data that
    a user will type in, it is a good idea to "clean" that data by at
    least replacing single quotes with two single quotes. This escapes the
    single quote and puts it into the data value and does not use it for a
    delimiter. For example: If comment was

    I'm Thirsty

    then your stmt section would be...

    ....,'http://www.myweb.com','I'm Thirsty')

    The single quote in I'm throws everything off.
    Dan Brussee Guest

  4. #3

    Default Re: INSERT INTO using HTML forms

    > stmt = "INSERT INTO Guest (Name, Location, Date, Email, Website,
    Comment)"
    > stmt = stmt & "VALUES ('" & Request.Form("Name") & "', '" &
    I imagine 'date' is a reserved word in Jet SQL, and possibly 'name' and
    some of the others too. In Jet SQL you can use a [...] syntax around
    table/column names to use reserved words, but these probably aren't good
    choices for column names anyway.

    MightyC



    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system ([url]http://www.grisoft.com[/url]).
    Version: 6.0.520 / Virus Database: 318 - Release Date: 18/09/03


    The Mighty Chaffinch Guest

Posting Permissions

  • You may not post new threads
  • You may 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