So i know that The invasion of the Ottoman Empire failed, but why did it?
The short version: The Ottomans defended well.
The longer version:
The British/Empire/French force failed to achieve their initial objectives in the attack. That is, they didn't reach the objectives they intended to capture on the first day. Not just not reach them on the first day, but they never captured them (by the end of the campaign, the forces at Cape Helles had gotten halfway to Achi Baba, their initial objective). This left the commanding high ground (i.e., the initial objectives: Achi Baba, dominated the tip of the Gallipoli peninsula, and Sari Bair ridge and Chunuk Bair, dominating the area to the north, and the initial objective for the ANZACs) in Ottoman hands, which eased their defensive problems by giving them better terrain to defend, providing them with excellent observation of the enemy positions, and artillery positions protected from naval bombardment.
The initial objectives were not ridiculous. It was about 9km from the tip of Cape Helles to Achi Baba, and significantly less from Y beach, the closest British landings to Achi Baba, and only about 2km to the high ground of Sari Bair and Chunuk Bair, the ANZAC objectives, from Anzac Cove. However, the terrain was difficult - very difficult - and maps were poor. Vigorous Ottoman defence made it impossible for these objectives to be reached.
There had been a chance. The Ottoman commander, von Sanders (Otto Liman von Sanders, the German commander of the Ottoman Fifth Army), expected a landing in the Gulf of Saros, at the base of the peninsula, and kept the 5th division off the peninsula, defending the east end of the gulf. This meant that the ANZACs faced only weak forces when they landed. Quick exploitation inland could have left Sari Bair and Chunuk Bair in their hands. However, a general breakdown of communications (and therefore of command and control) slowed the ANZAC advance, and very quick Ottoman reaction to the landings meant that progress was stopped. The 27th Regiment of the 9th Division, the northernmost regiment of the division covering the area from near the ANZAC landings to Cape Helles (the tip of the peninsula) only had very weak forces at Anzac Cove when the landings took place shortly after 4am. However, a large part of the regiment had arrived in the area and was able to counter-attack by about 8am. The 27th was greatly outnumbered, and took heavy losses, and would not have been able to stop the ANZACs for much longer. However, Mustafa Kemal (later Mustafa Kemal Atatürk), commander of the 19th Division covering the Dardanelles moved some of his forces into the area, and took over the defence, and held the ANZACs.
If the commanders of the 27th Regiment (Lieutenant-Colonel Sefik) and the 19th Division (Mustafa Kemal) had acted with less speed and worse judgment, it is possible that the ANZACs might have achieved their objectives.
The British landing at Cape Helles had less chance of reaching their objectives, which were further. Their best chance was the almost uncontested landings at beaches Y and X. The landings at X beach against very light resistance, and offered a chance at flanking the defenders of W beach (along the coast to the right of X beach), which would have allowed the forces at W beach to break out, and flank the defenders of V beach (at V beach, the landings went poorly, with the collier-turned-experimental-landing-ship River Clyde failing to successfully land its troops on the first day). However, prompt Ottoman reaction brought more defenders to X beach, and delayed the break out from X, W, and V beaches. The landings at Y beach were against very light defences, apparently only 9 men, reduced to 8 when one was sent as a messenger with news of the landings. Two and a half battalions got ashore essentially unopposed at Y beach, at the closest landing beach to Achi Baba. Two things went wrong: first, they failed to exploit inland as rapidly as possible (the advance inland stopped when they discovered their maps didn't describe the terrain accurately). Second, the Ottomans threw what forces were immediately available to defend Y beach into the fray. This only amounted to half a battalion, so the defenders were outnumbered 5 to 1. The Ottomans were very slow - there was a 5 hour delay - to bring further forces to defend the beach. However, the British were inert, and blessed the Ottomans with 5 hours of peace, allowing them to bring their defensive force to one and a half battalions. Still outnumbered, they counter-attacked effectively, and the British, believing that they were outnumbered and that the landing was hopeless, withdrew their forces from Y beach. The Ottomans considered the British inertia "a great stroke of luck".
After this, the British pushed inland from their landings at Cape Helles, but failed to reach Achi Baba. The ANZACs were held short of their objectives. The Allies had lost their chance of early success by not taking advantage of the initial gaps in the Ottoman defences, and having lost that chance, there were no more major gaps in the Ottoman defences. The Ottoman soldiers were well-equipped, well-trained, and well-motivated. The quality and tenacity of the Ottoman forces was essential for their successful defence - the defenders against the ANZACs, the 27th Regiment (Sefik) and the 57th Regiment of the 19th Division (Kemal) lost almost half their strength in the first 24 hours, but kept fighting. They were helped by the easily-defended terrain. Still, the 2nd day was difficult, since much of the original confusion and muddle of the landings had been rectified, and the ANZACs attacked with determination. The Ottomans held. After the 2nd day (26th April), the Ottoman defences grew stronger. At this point, unless much larger forces were committed by the Allies, they had no chance of victory. Their best attempt was the later landings at Suvla Bay (after more than 3 months of fighting), attempting to outflank the Ottoman defences containing the earlier landings, was stopped by quick Ottoman response, reminiscent of their reaction to the initial landings.
The Ottomans made a major effort to throw the ANZACs into the sea in mid-May. Despite a large numerical advantage (almost 3 to 1 against the ANZACS, in total, and about 2 to 1 counting the forces in the main attacks), this failed with heavy losses (over 30%), and the Ottomans mounted no further major offensives like this. This left the campaign in a protracted stalemate, where it continued until the withdrawal.
The key to Ottoman success was energetic commanders who reacted quickly to the initial landings, and tenacious defence by their soldiers. The quality of Ottoman leadership was maintained by the prompt removal of unsuccessful commanders by von Sanders (surely some merely unlucky commanders were removed, but it had the benefit of getting rid of incompetent commanders).
Why didn't the Allies expect such effective Ottoman defence? The Ottoman army had performed poorly in the Balkan Wars just a few years earlier. The Allies judged the Ottomans by their performance in those recent wars. However, the Balkan Wars had convinced the Ottomans that improvements and reforms were necessary, and they made those improvements. Success at Gallipoli was partly a result of that reform.
For a view of the defence of Gallopoli from the Ottoman side, see Harvey Broadbent, Defending Gallipoli: The Turkish Story, Melbourne University Press, 2015. Defending Gallipoli is his book on the topic for the general readership; his other book from 2015, Gallipoli, the Turkish Defence: The Story from the Turkish Documents (also MUP) is the technical version, longer, and with translations from Turkish documents.