I want to make a recipe website.In that I had added the add to favourite button.If i click my favourite button the recipe which i clicked will add to favourites.I i re-click it will remove from my favourites.It is controlled by the status field in the favourites table in sql.How could I do this?

If you want to delete the recipe from the favourites all together you could do the following

You need 3 tables:

  • UserTable

    • UserID (primary key)
  • RecipeTable

    • RecipeID (primary key)
  • FavouritesTable

    • FavouritesID (primary key)
    • UserID (foreign key)
    • RecipeID (foreign key)

You'll also need 2 stored procedures:

  • Insert
    stored procedure that is executed when the favourite box is and INSERTs a new record with the user's ID and the recipe ID

  • Delete
    stored procedure that is executed when the favourite box is unticked and DELETES a SINGLE record with that user's ID and the ID for that recipe.