To buy an item instantly (from a player who listed the item on market as a „sell order“) you simply open the market, search for the item, click on the item in the search results and then look at the top part of the window called „sell orders“. In this list, you‘ll see all people who are offering the item. In the lower half of the window you see people that put up a „buy order“ for the item.
If you already own the item you want to buy then you can also right click the item and select „view market details“. This saves you the effort of having to manually search the item in the market.
Next, ensure that you have the sell order list sorted by price (ascending) so you see the cheapest sell order at the top. Next, note WHERE the item is being sold (it will show you the name of the station the item is being sold on and how many jumps it‘s away from your current location).
Now you simply look for a sell order that is both cheap and close. Sometimes the only sell offers for your current location will be more expensive then if you flew a few jumps and bought it at some other location. You have to decide it the effort of flying a few jumps is worth it or if you‘re willing to buy an item for a slightly higher place right where you are.
Once you‘ve decided where to buy, you simply right click the sell order you prefer and say „buy“.
Now you confirm the transaction, the ISK is removed from your wallet and the item will appear in your hangar at the location where the seller listed it.
That‘s the normal procedure when instantly buying an item.
What you did was create a „buy order“ at your current location. This order will simply be added to the market and listed in the lower half of the market window under „buy orders“. Now the market will simply wait until someone is willing to sell you the item for the price you entered when creating your buy order. This order can either be fulfilled very quickly (for example if you enter a good price to your buy order) or it could take days, weeks or months before someone is found who is willing to sell to you at the listed price.
Setting up a „buy order“ usually only makes sense if you want to buy a large quantity of items or if you‘re willing to wait for someone who will sell you the item for a (presumably lower) price that you entered in your buy order.
So in general, when buying an item, simply search the market for a „sell order“ that fits your requirements (price and location) and right click -> buy.
I hope that clears things up.
PS. The reason your order disappeared (and was fulfilled) after you logged out and back in was likely due to some player selling you the item while you logged out and back in again. In this case, relogging didn‘t have any influence on the order. You could also just have waited (while staying logged in) until someone sold the item to you, thereby fulfilling your buy order.