"C White" wrote in message news:Ru********************@rogers.com...
: Bob Barrows [MVP] wrote:
:
: > C White wrote:
: >
: >>Sorry bout that, I wasn't sure if anyone would want it, here it is:
: >>
: >><%
: >>
: >>'declare your variables
: >>Dim Name, Email
: >>Dim sConnString, connection, sSQL
: >>
: >>' Receiving values from Form, assign the values entered to variables
: >>Name = Request.Form("Name")
: >>Email = Request.Form("Email")
: >
: >
: > You need validation code here to ensure these variables contain what you
: > expect. Use the len() function to verify that they contain data.
: >
: >>'declare SQL statement that will query the database
: >>sSQL = "INSERT into users (Name, Email) values ('" & Name & "', '" &
: >>Email & "')"
: >>
: >
: >
: > Since you are having a possible sql problem, you need to use basic
debugging
: > to make sure the sql statement contains what you expect:
: >
: > Response.Write sSQL
: > Response.End
: >
: > You can comment out the above lines when finished debugging. We need to
see
: > the resulting statement from the browser window. When using
concatenation to
: > create a dynamic sql statement, your goal is to create a statement that
will
: > run as-is in your database's query execution tool (the Access Query
Builder)
: >
: >
: >>connection.Open(sConnString)
: >
: >
: > Parentheses are not needed
: >
http://blogs.msdn.com/ericlippert/ar.../15/52996.aspx
: >
: >
: >>'execute the SQL
: >>connection.execute(sSQL)
: >
: >
: > Tell ADO what the command type is (adCmdText = 1) and that you are not
: > expecting any records back so it does not waste time and resources
behind
: > the scenes creating a recordset to receive the resultset
(adExecuteNoRecords
: > = 128)
: >
: > connection.execute sSQL,,129 '1 + 128 = 129
: >
: >
: > Bob Barrows
:
: the debugging code shows me the following, (when i set the database to
: allow zero length)
:
: INSERT into Users (Name, Email) values ('1st guy', '')
:
: if i move the hidden email field outside of my select code and just set
: it to
:
: <input type="hidden" name="TL_Email" value="em***@domain.com">
:
: everything works fine and it inserts the email, so this leeds me to
: beleive that there is indeed somethig wrong with the code I am using to
: create the drop box and that I should look at another way of doing it
:
: here is the full code i am using to generate the drop list
:
: <select name="Name">
: <%
: 'Dimension variables
: Dim adoConName 'Holds the Database Connection Object
: Dim rsName 'Holds the recordset for the records in the database
: Dim strSQLName 'Holds the SQL query for the database
:
: 'Create an ADO connection object
: Set adoConName = Server.CreateObject("ADODB.Connection")
:
: 'Set an active connection to the Connection object using a DSN-less
: connection
: adoConName.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" &
: Server.MapPath("User_Info.mdb")
:
: 'Set an active connection to the Connection object using DSN connection
: 'adoCon.Open "DSN=guestbook"
:
: 'Create an ADO recordset object
: Set rsName = Server.CreateObject("ADODB.Recordset")
:
: 'Initialise the strSQL variable with an SQL statement to query the
database
: strSQLName = "SELECT * FROM Names ORDER by Name ASC;"
:
: 'Open the recordset with the SQL query
: rsName.Open strSQLName, adoConName
:
: 'Loop through the recordset
: Do While not rsName.EOF
: %>
: <option value="<% Response.Write (rsName("Name")) %>">
: <% Response.Write (rsName("Name")) %>
: </option>
: <input type="hidden" name="Email" value="<% Response.Write
: (rsName("Email")) %>">
: <%
: 'Move to the next record in the recordset
: rsName.MoveNext
:
: Loop
:
: 'Reset server objects
: rsName.Close
: Set rsName = Nothing
: Set adoConName = Nothing
: %>
: </select>
:
: if anyone has suggestions please submit them, in the meantime i will
: re-evaluate how i am generating the drop box
Why is the hidden field inside the select? Are you associating different
email addresses with different names? If so, there are probably numerous
ways you could do that but one would be to have a hidden email list, not
just a hidden field and when posting your form, the index into the select
provides the index into your hidden list of email addresses and then
populates a hidden field in your form, outside of the select before
submitting. This way when the form is posted, the selected index provides
the name and the other [hidden or not hidden] element in the form for the
email address. Otherwise it appears all of your email addresses posted will
be blank.
I'm surprised that you do not get an error in your insert if the field is
set to require data for a record.
--
Roland Hall
/* This information is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose. */
Technet Script Center -
http://www.microsoft.com/technet/scriptcenter/
WSH 5.6 Documentation -
http://msdn.microsoft.com/downloads/list/webdev.asp
MSDN Library -
http://msdn.microsoft.com/library/default.asp