Main menu gets replaced when second menu is created

Maybe your second menu has the same id as your main menu when you registry these menus.
One more thing, make sure that you go to Dashboard > Appearance > Menus, tick to the box Location for the menus properly.

error code: 523