Inserting data into a table

Discussion in 'ASP General' started by Geoff Wickens, Aug 25, 2003.

  1. I am quite new to all this but am trying to create a database driven site. I
    have been able to use information from my sample database but I now want to
    be able to insert data into it. At present I put the data into my local copy
    of the access database and then upload it again to my server - not an ideal
    solution!

    I have tried using the INSERT command and it works fine if I enter the data
    into the statement. What I really want to do is collect the data from a form
    and then insert this into the database. My code is as follows:

    Page for collecting the data:

    <form name="useradd" method="post" action="testadd.asp">
    <p>Username:
    <input type="text" name="username">
    </p>
    <p>Password:
    <input type="text" name="password">
    </p>
    <p> Category:
    <select name="select">
    <option>member</option>
    <option>committee</option>
    <option>admin</option>
    <option>guest</option>
    </select>
    </p>
    <p>
    <input type="submit" name="Submit" value="Submit">
    <input type="reset" name="Reset" value="Reset">
    </p>
    </form>


    I then have the following code on the page (testadd.asp) to add this
    information to my database.

    <%
    u = Request.Form("username")
    p = Request.Form("password")
    c = Request.Form("category")

    Set Catalog=Server.CreateObject("ADODB.Recordset")
    Catalog.open "INSERT INTO tbltest (username, password, category) VALUES (u ,
    p, c)", "DSN=members"
    %>

    The thing which goes wrong is the VALUES part of the statement. It seems to
    want 'u' etc but then puts in this text rather than the contents of my
    variable.

    Any help most welcome.

    Geoff Wickens
     
    Geoff Wickens, Aug 25, 2003
    #1
    1. Advertising

  2. Geoff Wickens

    only me Guest

    You forgot to reference the actual data itself

    INSERT INTO tbltest (username, password, category)
    VALUES (' " & u & " ',' " & p & " ',' " & c & " ')

    note use of single quotes to delimit the text fields - I have put extra
    space between single and double quote to be clear - you should remove other
    wise your stored data will have leading and trailing space


    "Geoff Wickens" <> wrote in message
    news:NSk2b.142$...
    > I am quite new to all this but am trying to create a database driven site.

    I
    > have been able to use information from my sample database but I now want

    to
    > be able to insert data into it. At present I put the data into my local

    copy
    > of the access database and then upload it again to my server - not an

    ideal
    > solution!
    >
    > I have tried using the INSERT command and it works fine if I enter the

    data
    > into the statement. What I really want to do is collect the data from a

    form
    > and then insert this into the database. My code is as follows:
    >
    > Page for collecting the data:
    >
    > <form name="useradd" method="post" action="testadd.asp">
    > <p>Username:
    > <input type="text" name="username">
    > </p>
    > <p>Password:
    > <input type="text" name="password">
    > </p>
    > <p> Category:
    > <select name="select">
    > <option>member</option>
    > <option>committee</option>
    > <option>admin</option>
    > <option>guest</option>
    > </select>
    > </p>
    > <p>
    > <input type="submit" name="Submit" value="Submit">
    > <input type="reset" name="Reset" value="Reset">
    > </p>
    > </form>
    >
    >
    > I then have the following code on the page (testadd.asp) to add this
    > information to my database.
    >
    > <%
    > u = Request.Form("username")
    > p = Request.Form("password")
    > c = Request.Form("category")
    >
    > Set Catalog=Server.CreateObject("ADODB.Recordset")
    > Catalog.open "INSERT INTO tbltest (username, password, category) VALUES (u

    ,
    > p, c)", "DSN=members"
    > %>
    >
    > The thing which goes wrong is the VALUES part of the statement. It seems

    to
    > want 'u' etc but then puts in this text rather than the contents of my
    > variable.
    >
    > Any help most welcome.
    >
    > Geoff Wickens
    >
    >
     
    only me, Aug 25, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bhavesh
    Replies:
    0
    Views:
    426
    Bhavesh
    Jul 16, 2007
  2. Bhavesh
    Replies:
    5
    Views:
    634
    Bhavesh
    Jul 18, 2007
  3. Bhavesh
    Replies:
    1
    Views:
    452
    Bhavesh
    Jul 17, 2007
  4. Renie83
    Replies:
    1
    Views:
    179
    Kiran Math
    Jul 10, 2003
  5. Cooper Deford
    Replies:
    2
    Views:
    155
    Cooper Deford
    Jul 22, 2008
Loading...

Share This Page