Forums

This topic is locked

Check if a record already exists on a table

Posted 29 Aug 2001 04:32:42
1
has voted
29 Aug 2001 04:32:42 B. B. posted:
Hello! Have a site that has three tables. The first is the Users table
which has a record inserted when a new user registers correctly.

Another function in the site is to insert a record on table 2 which will
contain the username, it was put in a session variable, and a product
column. The Insert Record Behavior is used to do this with a form
field containing drop down items for the product.

When the user clicks the Insert Record button on this form would like
to make sure they do not already have a record on this second table.
What is the best way to do this? Have some scenarios that follow.

1) Possibly add the CheckUserName behavior to this page too. Multiple
behaviors can be on one page. Is this possible, how would it check this
when the Insert Record button is clicked?

2) Make another recordset on the page, pass the username from the
session variable to the SQL and check if any rows are returned. If so then
pop up a message indicating a record is already on the table and that you
must
go to the Update table2 page. Where would this new recordset be put? Would
guess somewhere before the Insert Record behavior code was placed.
Is that correct. How would you invoke the function or whatever to check if
the
new recordset returned a row in the recordset.totals field when the
Insert Record button is clicked.

It looks like UltraDev creates some kind of mm_editAction function that
is run upon the button click. Can the recordset.total be checked in there
and have
an error message displayed and return a value of false so the Insert does
not complete
fully?

Not sure if the above two are valid scenarios or if there is an existing
behavior that
could be used for this. Would greatly appreciate any help. Thanks!




Replies

Replied 29 Aug 2001 13:19:53
29 Aug 2001 13:19:53 Joel Martinez replied:
well, I'm not familiar with the check username behavior, but if you can use that to check for the username in the second table, then that's what you should use... Just do that on a sort of pre-processor to the page that would let them insert to table2, and if they don't have a record, redirect to the insert page, if they do, redirect to an error page.

you can also use scenario 2 in the same fashion... if there's not an extension to do this, just add this after the recordset behavior:<pre id=code><font face=courier size=2 id=code>&lt;%
if recordset1.eof then
response.redirect("insertPage.asp"
else
response.redirect("alreadyHaveRecord.asp"
end if
%&gt;</font id=code></pre id=code>That should take care if it.

Joel Martinez [ ]
----------
set rs = conn.execute("SELECT answer FROM brain WHERE question = "& forumPost &"
'2nd place is just 1st Loser

Reply to this topic