Gossamer Forum
Home : Products : DBMan : Customization :

Add one record and then no more?

Quote Reply
Add one record and then no more?
Anybody have a quick and easy way of:
1. After a user enters a record, user cannot add another record but still can modify/delete there own, (which does work).
2. The ideal way is when the user signs on, it checks for the userid in the data base, and then takes off the permission for add. Also need to set it after user adds there record the first time.
(I do have the the "auth_user_field" set to one and for "userid").
I have seen other post about this, but for some reason it did not fit the bill or I missed something.
Any help will truly be appreciated.
Quote Reply
Re: Add one record and then no more? In reply to
There are several ways to do this.

The first is to set the $db_key to the userid field. If a user tries to add a second record, he will get a "duplicate key" error. It is effective, but it does still leave the "Add" link in the footer menu. It is the easiest way, though.

Another way is to do a search for a user's record when they log on. If a record is not found, the user is moved automatically to the add record page. If one is found, the user gets the home page. With this option, you would remove the "Add" link from the footer menu. This would probably be the way to go if you are requiring all registered users to have a record in the database. It would probably be a good idea not to have the footer menu on the add record form at all, if you did this. Also, in case the user tried to get around your precautions, it would probably be best to set the $db_key to the userid field. That way, if he does manage to get to the add record form, his second record wouldn't be accepted.

A third way would be to change the permission in the password file after a user adds a record. This would be appropriate if you are not requiring the user to have a record in the database in order to be able to view other records. You would also need to change the permissions again, if the user deleted his record.

I can help you with whichever of these options you'd like, if you tell me which one you're interested in.


------------------
JPD


Quote Reply
Re: Add one record and then no more? In reply to
Thanks for your reply Mr JPDeni.
I was considering the db_key, but we also do not want any duplicate ID numbers. It is auto incremented and hidden except in the default user view. Anybody can search, just the sign on user can create one record and thats it. Just thinking if that would pose a problem under any possible scenario when multiple users are adding at the same time, or on deleting a record with out having the db_key on the ID #. I suppose the best of both worlds is to have 2 db_key's. hmmmm.
Your thoughts on this?
Quote Reply
Re: Add one record and then no more? In reply to
Not that I'm offended in the least, but just keeping the record straight, it's Mrs. JPDeni! Smile

Quote:
Just thinking if that would pose a problem under any possible scenario when multiple users are adding at the same time, or on deleting a record with out having the db_key on the ID #.

Not at all. In fact, if you don't have another use for an ID#, there's no reason to have that field at all. Just use the userid as the key.

DBMan doesn't care what the key is -- whether it's numbers or letters or any combination. The only thing with the db_key is that it must be unique for each record.

There also shouldn't be a problem if more than one person is accessing the database, so long as you have flock on. Or are you on a Windows system?

Quote:
I suppose the best of both worlds is to have 2 db_key's. hmmmm. Your thoughts on this?

Not possible in DBMan.

------------------
JPD


Quote Reply
Re: [JPDeni] Add one record and then no more? In reply to
how would you search to see if the user has a record in the database? if the user doesn't have a record then the option would be there for them to add a record... but if the record is found then the 'add' link is removed...
Quote Reply
Re: [haagendoss] Add one record and then no more? In reply to
Taken from the FAQ under admin section:

To force users to add a record when they first log on, add the following to the beginning of

sub html_home:

%rec = &get_record($db_userid);
if (!%rec) {
&html_add_form;
return;
}

This assumes that you are using the userid field as the key field. You might also want to take out the call to &html_footer in sub html_add_form, so they don't see that they have other options.

There are other related threads available in the FAQ under the section "Admin" if this is not the solution you were looking for.

Unoffical DBMan FAQ

http://creativecomputingweb.com/dbman/index.shtml/