Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question inserting into a database from a drop down menu

    does anyone have any idea of inserting to a database a value that the user chooses from a drop down menu in a form. something like:

    <p>Choose a branch: <select name="select">
    <option>Bristol</option>
    <option>Leeds</option>
    <option>London</option>
    <option>Manchester</option>
    </select> </p>


  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    262
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yep,

    Choose a branch:
    <form> - add your method and action in here
    <select name="cboBranch">
    <option value="Bristol">Bristol</option>
    <option value="Leeds">Leeds</option>
    <option value="London">London</option>
    <option value="Manchester">Manchester</option>
    </select>
    </form>

    <%
    request.form("cboBranch")
    %>

    Now you just insert this value into your database like any other one.


  • #3
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    actually in my from i have few drop down menus and few texts to be inserted into the database.

    so i just use 1 form action as a whole the thing is how to write insert into sql statement.is it something like:

    strSQL = "INSERT INTO Customer (Branch, News, Resources) Values('" & Option & "','" & option& "','" & option & "',)"



  • #4
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy

    I have tried to insert data from the drop down menus into the database with the code:

    <%@ Language = "VBScript"%>
    <%


    'Declare all local variables
    dim conn
    dim rs
    dim strconn
    dim strSQL
    Dim strCustomer_Name
    Dim strCustomer_Address
    Dim strCustomer_Postcode
    Dim strCustomer_Phonenumber
    Dim strCustomer_Email

    strCustomer_Name = Request.Form("Customer_Name")
    strCustomer_Address = Request.Form("Customer_Address")
    strCustomer_Postcode = Request.Form("Customer_Postcode")
    strCustomer_Phonenumber = Request.Form("Customer_Phonenumber")
    strCustomer_Email = Request.Form("Customer_Email")
    Branch_Code = Request.Form("Branch")
    Resource = Request.Form("Resource")
    Future_News = Request.Form("Future")
    Interested_Topic = Request.Form("Topic")

    If Len (strCustomer_Name) > 0 Then




    Set conn = Server.CreateObject("ADODB.Connection")
    'set connection string to local variable-I use a DSN-less connection
    'Need to modify just this line.Point to right path to database file.
    conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\anticus\db\deneme.mdb"))
    'build the sql statement based on the input from the form
    strSQL = "INSERT INTO [Customer Contact Details](Customer_Name, Customer_Address, Customer_Postcode, Customer_Phonenumber, Customer_Email ) Values('" & strCustomer_Name & "','" & strCustomer_Address & "','" & strCustomer_Postcode & "','" & strCustomer_Phonenumber & "','" & strCustomer_Email & "')"
    strSQL = "INSERT INTO Customer (Branch_Code, Resource, Future_News, Interested_Topic) Values ('" & Branch_Code & "','" & Resource & "','" & Future_News & "','" & Interested_Topic & "',)"
    Response.Write(strSQL)
    conn.execute(strSQL)

    Session("Customer_Name") = strCustomer_Name
    conn.close
    set conn = nothing

    end if



    %>



    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>


    <form action="customer details.asp" method="post"name="RegisterForm">

    <p>Your name: <input type="text" name="Customer_Name"></p>
    <p>Your address: <input type="text" name="Customer_Address"> </p>
    <p>Your postcode: <input type="text" name="Customer_Postcode"> </p>
    <p>Your Phone Number: <input type="text" name="Customer_Phonenumber"> </p>
    <p>Your e-mail address: <input type="text" name="Customer_Email"></p>
    <p>Choose a branch: <select name="Branch">
    <option value="Bristol">Bristol</option>
    <option value="Leeds">Leeds</option>
    <option value="London">London</option>
    <option value="Manchester">Manchester</option
    </select> </p>
    <p>Choose the topics you are interested in: <select name="Topic">
    <option value="Listening">Listening</option>
    <option value="Writing">Writing</option>
    <option value="Reading">Reading</option>
    <option value="Listening, Writing">Listening, Writing</option>
    <option value="Listening, Reading">Listening, Reading</option>
    <option value="Writing, Reading">Writing, Reading</option>
    <option value="All">All</option>
    </select> </p>

    <p>Would you like to hear more about news? <select name="Future">
    <option value="Yes">Yes</option>
    <option value="No">No</option>

    </select> </p>
    <p>Where have you heard about us? <select name="Resource">
    <option value="Brochure">Brochure</option>
    <option Value="Friend">Friend</option>
    <option value="Internet">Internet</option>

    </select> </p>

    <input type="SUBMIT" name="SUBMIT" value="SUBMIT">

    <p>&nbsp;</p>
    </form>
    </body>
    </html>


    but when i view the page the Topic drop down menu doesn't seem like a drop down menu on the page instead the values are listed next to branch drop down menu as text.

    When I submit the form with this it gives me syntax error because of not inserting any value from topics. I couldn't find out the reason of it...any ideas pls?

  • #5
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    First of all, you have a space in your file name. "customer details.asp".

    I would definitely rename this, spaces aren't good to have in file names.

    The reason your options are showing up on the page (and not being "requested" by your second asp page) is that you left a closing bracket off of an </option> tag on line 74:

    <option value="Manchester">Manchester</option>

    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #6
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    yeah i have just noticed my mistake 5 mins ago.but thanks anyways...great help


  •  

    Posting Permissions

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