View Full Version : inserting into a database from a drop down menu

02-09-2003, 03:12 PM
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">
</select> </p>


02-09-2003, 03:56 PM

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>


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


02-09-2003, 04:03 PM
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 & "',)"


02-10-2003, 10:14 PM
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 & "',)"

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

end if


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


<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">


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?

02-11-2003, 01:30 AM
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>


02-11-2003, 01:32 AM
yeah i have just noticed my mistake 5 mins ago.but thanks anyways...great help:thumbsup:

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum