Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to add to a db from drop down menu

Status
Not open for further replies.

adolsun

Programmer
Jan 13, 2004
52
GB
l've created an Access db with these fields (Title, Body and Section) Section field is Lookup column (About Me, Contact and Links). Also I created a form on add_data.asp to add data from it. On the form there's a Drop Down Menu. The peoblem is how to add from the drop down menu to the database. Here's my code:

Note that I have no problem to add data to my db eccept with this drop down menu!



<%@language=VBScript>
<html>
<BOD>
<!--#include file="connection.txt"-->
<%
section=request.form("section")
title = request.form ("title")
body = request.form ("body")

If title="" or body="" then
response.write "<center>" & "Please re-enter your data again !"
Else
addSQL= " insert into project (section,title,body) values ('"&section&"','"&title&"','"&body&"') "
ADO.execute(addSQL)

response.redirect "add_data.asp"
End if
%>

<form method="POST" action="add_data.asp">
<p>Section:

<select size="1" name="section">
<option value="About Me">About Me</option>
<option value="Links">Links</option>
<option value="Contact">Contact</option>
</select></p>
<p>Title: <input type="text" name="title" size="20"></p>
<p>Body: <input type="text" name="body" size="20"></p>
<p><input type="submit" value="ADD" name="add"></p>
</form>
<%
ADO.close
Set ADO=Nothing
%>
</body>
</html>


Thanks in advance !
 
Take a look at this recent thread...

thread333-960460

-L
 
I read this before I sent my threate. The difference is the databse. On my case I have a lookup column not a field to enter data into it.

Hope you got it.
 
Actually, I don't see the difference. Whether or not you have a lookup table you still have to put the data for that sleecteion somewhere. Having a lookup table just means that you can put a numeric id somewhere instead of the full word. I'd suggest putting that id from the lookup table in the value for those options, like it was done in the thread Lothario linked to. Then you would be passing the id as the selected value and would need to use your lookup table later on to get the text value back out of the db.

-T

barcode_1.gif
 
I got it. I tried putting [] around the column names in sql command, in case one of column names is a reserved word.

Thanks to you all.
 
Hi

You need to validate the values being passed in or someone could run malicious [SQL Injection] code against your database or alternative ASP.......

Just a thought



Glen
Conception | Execution
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top