tags:

views:

87

answers:

1

Hi Friends I develop a webpage in that i face this problem. please see below.

In user table i have following fields:

  • Userid
  • password
  • Address
  • phone
  • Email

In service table i have the following fields:

  • Ser_name
  • ser_id
  • USER_Refid

All these are in same page in php.

When i add values in service table it stores under the same USER_Refid name .

For example the user xxxx is going to add service means the USER_Refid field contain the same name for all services .

My problem is when the user add values in services table and forgot to add the values in user table means i want to delete the values that inserted by that particular user . Please help me to solve this , Thanks in advance.

A: 

If your tables are InnoDB, you can a FOREIGN KEY constraint to your service table:

ALTER TABLE service_table ADD CONSTRAINT fk_service_user_refid FOREIGN KEY (USER_refid) REFERENCES user_table (USER_id)

To add the values into services, create a memory table with a session id, populate it with your services, and when the user clicks Save, do the following:

  • Create an entry for your user in the user_table
  • Move the entries from the temporary table into the service_table.
Quassnoi
At first user can able to add values to service table without store values into user table.[Just to give the value in that Userid field ,the service table take that value for the field USER_Refid]
Sakthivel
Your criteria will apply if the user first store the values in to user table
Sakthivel
Why don't you want to add to the user table first? If your service table records cannot exists without an entry in user table, this makes more sense.
Quassnoi
then what you mean you said can add service without any user then said you want delete whom add service without any reference?
Am1rr3zA
That means i used those all in a single page in php . i ask user to enter the userid first and make it as readonly . After that he can add values to the service table. So i can take that readonly field value for USER_refid field .After add many services, the user click the save all button means i insert the value into user table.
Sakthivel
`@Sakhtivel`: for some strange reason you make the `user` entry temporary and `service` entries permanent. Just put your services into a temporary table, and when the user clicks `Save`, move them into the permanent table.
Quassnoi