Forum Moderators: open

Message Too Old, No Replies

Verify data before sending to dbase?

         

tonynoriega

11:14 pm on Feb 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good morning,afternoon,evening...

can you verify form field values before sending them to a database?

I dont want to verify IF a value is there, or IF the value is of proper format...

I want to, for instance, see if a record already exists...

In my form, if you enter John for the first name, and Smith for the last name, when you hit "submit" it will query the dbase for that combination of values, and alert if it already exists...

If it does you can cancel, of it doesnt, it will submit.

LifeinAsia

12:00 am on Feb 6, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Of the top of my head I can think of 2 ways to do it:
1) Use AJAX to check before you submit the form to the next page.
2) On the submitted page check to see if already exists. If so, return to previous page, otherwise insert the data.

ZydoSEO

12:11 pm on Feb 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you konw which fields identify a unique consumer, put a unique index on those fields. Simply always attempt to do the insert. If the insert succeeds then this was the first time you've added them. If it fails then check the return status. Hopefully, the DB you're using will return an error number/status that you can use to determine why it failed. Should be some value that indicates something to the affect of 'Duplicate key violation'. When you see this error returned, you know it already exists.

Performing a query before each attempt to insert seems inefficient to me as you are performing a SELECT + an INSERT for users that don't already exist. With the approach above you only attempt 1 SQL statement per attempted transaction.

jtara

10:32 pm on Feb 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



can you verify form field values before sending them to a database?

Of course you can. You will have to modify whatever script is accepting the data, of course.

My favorite refrain from working on a 15-person multi-million dollar software project, when asked by the CEO "can you do...."

"We can DO anything!"

("It's just a matter of cost and effort.")

IF you are using a database that supports triggers, AND your existing scripts handle errors in an intelligent manner, you MIGHT get away with simply adding triggers to the database validate the data.

But probably not.