My form structure is like this in which fields[] input can be added any number of times at time of submission of form.Here i am storing website link in fields[] .
<input id="name" name="name" type="text" />
<input id="field_1" name="fields[]" type="text" />
<input id="field_2" name="fields[]" type="text" />
<input id="field_3" name="fields[]" type="text" />
I have managed to store this data in a MySQL database using the table structure below to allow a user to be associated with an unlimited number of websites:
Users User_website_link Websites
------ ----------------- ---------
Pk:UserID Pk:ID Pk:WebsiteId
name UserID Url
WebsiteID
Let say user fills following data in form {“Jon”, “example.com”, “example1.com”, “example2.com” }
So after submitting form table would be looking like this:
User table:
UserID Username
1 Jon
Websites Table:
WebsiteID Url
1 example.com
2 example1.com
3 example3.com
User_website_link Table:
ID UserID WebsiteId
1 1 1
2 1 2
3 1 3
How should I allow the user to edit their URLs after submitting them?
So my question is: a user called John wants to delete example3.com and edit example.com to demo.com, So I want to know how to delete some websites from the database and edit some.
You don’t need the user_website_link table – you can just put a UserID in another column in your websites table.
But to answer the question:
You do not need to edit entries, simply add another column that is something like boolean
is_deletedand only display or use URLs that have theis_deletedas false. So you just let the user add an extra URL for editing, and just set theis_deletedwhen you delete them. Of course you could remove that row on deletion, or clear deleted ones later, but I think this method is slightly easier.