".....Whereas Allah permitteth trading and forbiddeth usury (riba)...."
(Qur'an. Al-Baqara : 275)
Investing in stock market means you buy shares/ownership of a company that trade something. There is no prohibition for it. So, invest you money in stock market is halal.
However, although your share is only 0.00000000001% and you hold those shares only for few days, you are still the owner of that company. And, as Muslims you are not allowed to sell/trade haram stuff. Of course, you cannot hold shares from companies that sell/trade pork, alcohol. Also cannot invest in casino/gambling companies, conventional (riba based) banks and conventional insurances.
Out of those companies, there are other companies that probably categorized as haram companies, like cigaret companies, weapons manufacturer, movie maker companies and hotels.
Before you buy shares from stock market you must check, what company is that. Or if there is Islamic Index in that stock market, you can invest your money in companies at this Index.
There are two way to get gain from stock market.
First. You buy shares from a company, then you get dividend (profit sharing) from this company. This is halal because there is no prohibition for profit sharing.
Second. You buy shares then sell it when the price is going higher, and you get gain. This is also halal because this is trading. Read ayaah from surah Al-Baqara above.
But remember, everything was created in pair. There is gain, there is loss. You can get profit in stock market, but also you can lose your money.