the name attribute is used for posting to e.g. a webserver. The id is primarily used for css (and javascript). Suppose you have this setup:
in order to get the value with PHP when posting your form, it will use the name-attribute, like this:
$_POST["message_name"];
The id is used for styling, as said before, for when you want to use specific css.
#message_id
{
background-color: #cccccc;
}
Of course, you can use the same denomination for your id and name-attribute. These two will not interfere with each other.
also, name can be used for more items, like when you are using radiobuttons. Name is then used to group your radiobuttons, so you can only select one of those options.
And in this very specific case, I can further say how id is used, because you will probably want a label with your radiobutton. Label has a for-attribute, which uses the id of your input to link this label to your input (when you click the label, the button is checked). Example can be found below