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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking values in a db from form

Status
Not open for further replies.

DeepBlerg

Technical User
Jan 13, 2001
224
AU
Hi,

Say for example my db is named: testdb
with a table called: testtbl

I would like it so if a user fills out a form, the ASP page checks to see if the email entered is in the db then checks along that record to see if "wantsinfo" is set to "ON" then if all of that is true redirects them to found.htm and if false or found email but "wantsinfo" is set to "OFF" adds the new record.

See below:
<%
email=request.form(&quot;email&quot;)
wantsinfo=request.form(&quot;wantsinfo&quot;)

Set dbconnection = Server.CreateObject(&quot;ADODB.Connection&quot;)
dbconnection.open &quot;DSN=testdb&quot;

Set RS_Users = Server.CreateObject(&quot;ADODB.Recordset&quot;)

RS_Users.ActiveConnection = dbconnection
RS_Users.Source = &quot;testtbl&quot;
RS_Users.CursorType = 1
RS_Users.CursorLocation = 2
RS_Users.LockType = 2
RS_Users.Source = &quot;testdb&quot;

SQL_Users = &quot;Select * from testtbl where email = '&quot; &amp; email1 &amp; &quot;'&quot;
SQL_Users = &quot;Select * from testtbl where wantsinfo = &quot;ON&quot;
RS_Users.Open SQL_Users

If RS_Users.eof then
RS_Users.AddNew
RS_Users(&quot;email&quot;) = email
RS_Users(&quot;wantsinfo&quot;) = wantsinfo
RS_Users.Update
else
response.redirect(&quot;found.htm&quot;)
end if
RS_Users.close
Set RS_Users=Nothing
dbconnection.close
%>


Where am I going wrong?

Thanks for any help you could give me :)

--Tim
 
I suppose this is where you go wrong:

SQL_Users = &quot;Select * from testtbl where email = '&quot; &amp; email1 &amp; &quot;'&quot;
SQL_Users = &quot;Select * from testtbl where wantsinfo = &quot;ON&quot;
RS_Users.Open SQL_Users

The way you coded your SQL statement, only the second line will be executed (Select * from testtbl where wantsinfo = &quot;ON&quot;). I think your code should be:

SQL_Users = &quot;SELECT * FROM testtbl WHERE email = '&quot; &amp; email1 &amp; &quot;'&quot;
SQL_Users = SQL_Users &amp; &quot; AND wantsinfo = 'ON'&quot;
RS_Users.Open SQL_Users


<webguru>iqof188</webguru>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top