A survey of commentaries on the OP's question reveals a variety of opinions. Most modern and contemporary scholars see the accounts as referring to the same event but there is a wide divergence of opinion regarding the apparent differences in detail and how they might be resolved.
The NAB Bible says of John 12's account:
[12:1–8] This is probably the same scene of anointing found in Mk
14:3–9 and Mt 26:6–13. The anointing by a penitent woman in Lk 7:36–38
is different. Details from these various episodes have become
interchanged.
The Enduring Word Commentary sees the two accounts as definitely referring to the same event and attempts to show how they dovetail without contradiction:
It seems that this dinner [in John's account) was at the home of Simon the Leper (Matthew
26:6 and Mark 14:3). His friends Martha, Lazarus, and Mary were also
in attendance. Because Martha seems to be the hostess, some think
Simon the Leper was related to Mary, Martha, and Lazarus or even that
he was Martha’s husband. If common customs were followed, this dinner
was for the men of the village and Martha and the other women served.
The Interpreter's Bible is more willing to accept differences in details:
The scene is comparable to the account in Mark 14:9, with details that
also recall the incident in Luke 7:36-50. It differs from the Synoptic
story in being placed before the Triumphal Entry... It differs further in
being located in the home of Lazarus rather than of on Simon the
leper.
An older commentary (Benson's) reports that the question is perplexing, resulting an a scholar who once agreed with the older view - that these two two different events - changing his mind after reflection:
“Few passages,” says Dr. Doddridge, “in the harmony [of
the gospels] have perplexed me more than this. I was long of opinion,
with Origen and Theophylact, defended by Le Clerc and Dr. Whitby, and
especially by Dr. Lightfoot and Mr. Whiston, that the story recorded
by Matthew and Mark is different from this in John. But on maturer consideration, it appears to me more probable that Matthew and Mark should have introduced this story a little out of its place."
Meyer opines that
The peculiarity of John’s account is founded on the fact of the
writer’s being an eye-witness; but is referred by Baur, p. 256 ff., to
an eclectic and arbitrary treatment, dependent on an ideal point of
view; comp. also Hilgenfeld.
The Pulpit commentary, meanwhile, says
[The Synoptics'] purpose was not a chronological one. They give the
narrative of the anointing apart from its deepest meanings and
consequences, apart from any references to Lazarus (see Matthew
26:6-12; Mark 14:1-11). There are other subtle omissions from the
synoptists, the difficulties of which must be settled as between
themselves.
From the above we can see that scholars are far from united in their opinion of the OP's questions. Generally, it is fair to say that while older writers often spoke of two different events (Origen, Le Clerc, Lightfoot) modern scholars tend to see it as referring to a single event; but some are willing to admit to important differences in detail.