Copy link to clipboard
Copied
What I have is a user input field that I want to check against 4 separate fields in the database. I know the code for errors on the one field by making it unique, but I need to check all 4 fields and not allow it be sent the database if the value in the user field matches any of the 4 fields in the database. I hope that makes sense...can anyone help me with this? FYI - they are picture fields so I don't want someone to have matching names of pictures.
Copy link to clipboard
Copied
It sounds as though your database structure is probably at fault, but if you want to check a single value in four fields, create a recordset like this:
SELECT id FROM mytable
WHERE field1 = myval OR field2 = myval
OR field3 = myval OR field4 = myval
In the Variables section of the Advanced Recordset dialog box, set Name to myval, Type to text, and Runtime Value to $_POST['input_name'] (obviously, change the various names to match your setup).
Let's say you call the recordset "check", you can then use $totalRows_check to see if there are any matches. If there aren't, let the insert go ahead.
if ($totalRows_check == 0) {
// the insert record server behavior code goes here
} else {
// redisplay the form with an error message
}
Dreamweaver always puts the code for recordsets immediately above the DOCTYPE declaration, so you will need to move the code around yourself to check whether there are exisiting records before allowing the insert to go ahead.
Copy link to clipboard
Copied
Thanks, I didn't think to do it that way. It works perfect!
Copy link to clipboard
Copied
Marking this thread as assumed answered.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now