close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

How can I check if a record exists before inserting

Thread began 5/05/2009 5:40 am by doggyDivemaster | Last modified 6/03/2009 12:12 pm by meister281653 | 13188 views | 25 replies |

doggyDivemaster

How can I check if a record exists before inserting

I need to check whether a record already exists with the same description as that in a form being submitted for insert by DataAssist and, if it does, don't insert and redirect.

Previously, I could have fudged it by using Dreamweaver's 'Check New Username' behaviour and substituting my description field for the behaviour's username.

I need to use the DataAssist insert record behaviour because I am also using Digital File Pro on the same page but Check New User Name doesn't work with DataAssist's insert record behaviour.

Is their an easy way to check if a record exists prior to insert using WebAssist's tools?

Sign in to reply to this post

Danilo Celic

One way to do this would be to apply to a test page the built in Dreamweaver Insert Record and the Check New User Name using the same connection/table/column that you want to check in the "real" page. Then copy and paste the code for the Check New Username over to your real page.

This method will likely show a red exclamation mark next to the Check New Username in the Server Behaviors panel due to there not being a built in Dreamweaver Insert Record on the page, but it should work for you as long as you make sure to copy over all of the Check New Username code.

Sign in to reply to this post

doggyDivemaster

Thanks, I needed to check whether there was a built-in DataAssist behaviour but as there wasn't, I have followed your advice.

Because I was ALSO inserting the filename from a file uploaded by WA DigitalFilePro, I had to modify the Check New User Name code.

Here it is for anyone else reading this post. I have commented out the Dreanweaver lines I had to modify.

' *** Redirect if username exists
'MM_flag = "MM_insert" ***** Removed
'If (CStr(Request(MM_flag)) <> "") Then *****Replaced code with the line below
if (cStr(WA_DFP_UploadObj.Form("Insert.x")) <> "") Then
Dim MM_rsKey
Dim MM_rsKey_cmd

MM_dupKeyRedirect = "index.asp"
'MM_dupKeyUsernameValue = CStr(Request.Form("jobDescription")) *****Replaced code with the line below
MM_dupKeyUsernameValue = cStr(WA_DFP_UploadObj.Form("jobDescription"))
Set MM_rsKey_cmd = Server.CreateObject ("ADODB.Command")
MM_rsKey_cmd.ActiveConnection = MM_printShop_STRING
MM_rsKey_cmd.CommandText = "SELECT jobDescription FROM jobDescriptions WHERE jobDescription = ?"
MM_rsKey_cmd.Prepared = true
MM_rsKey_cmd.Parameters.Append MM_rsKey_cmd.CreateParameter("param1", 200, 1, 50, MM_dupKeyUsernameValue) ' adVarChar
Set MM_rsKey = MM_rsKey_cmd.Execute
If Not MM_rsKey.EOF Or Not MM_rsKey.BOF Then
' the username was found - can not add the requested username
MM_qsChar = "?"
If (InStr(1, MM_dupKeyRedirect, "?") >= 1) Then MM_qsChar = "&"
MM_dupKeyRedirect = MM_dupKeyRedirect & MM_qsChar & "requsername=" & MM_dupKeyUsernameValue
Response.Redirect(MM_dupKeyRedirect)
End If
MM_rsKey.Close
End If
%>


SUGGESTION - You should add this invaluable behaviour to DataAssist

Sign in to reply to this post

Ray BorduinWebAssist

Another option is to create a recordset filtered by the field you want unique and then use validation toolkit to validate the result returns zero records. That is the method I prefer.

Sign in to reply to this post
Did this help? Tips are appreciated...

meister281653

How does that work?

Sign in to reply to this post

Ray BorduinWebAssist

You create a recordset filtered by the form element, say the email address... then that recordset will set a record count variable. You use that variable in validation toolkit and validate it as a number that is equal to zero. If it isn't zero the validation fails.

This is how it is done in the User Registration Solution and the Powerstore solution if you happen to have them as examples.

Sign in to reply to this post
Did this help? Tips are appreciated...

meister281653

No I dont have em. I got Validation tool kit, security assist and dataassist.

Hmm, I dont understand that. where do i create the record? in the page of the form?

Sign in to reply to this post

Ray BorduinWebAssist

You create the recordset and add validation on the action page of the form, the same page that has the insert server behavior applied.

Sign in to reply to this post
Did this help? Tips are appreciated...

Ray BorduinWebAssist

Look through the forums, I have walked several people through the process in the past.

Sign in to reply to this post
Did this help? Tips are appreciated...

paul377172

I've read through the other forums and looked at the run through, but I'm using asp it doesn't help reading the php coding.

I know you create a recordset and filter it by the field you want to use but when you goto server vaildation, what do you choose as your validation type "number" ? then do you choose server variable as total records in the recordset.

Whatever I have tried hasn't worked for me

Your support here would be appreciated.

Sign in to reply to this post
loading

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...