Do I make money in the stock market from other people losing money?
The stock market as a whole, on average, increases in value over time. So if we make the claim that the market is a zero-sum game, and you only make money if other people lose money, that idea is not sustainable. There aren't that many people that would keep investing in something only to continue to lose money to the "winners."
The stock market, and the companies inside it, grow in value as the economy grows. And the economy grows as workers add value with their work.
Here's an analogy: I can buy a tree seed for very little and plant it in the ground. If I do nothing more, it probably won't grow, and it will be worth nothing. However, by taking the time to water it, fertilize it, weed it, prune it, and harvest it, I can sell the produce for much more than I purchased that seed for. No one lost money when I sell it; I increased the value by adding my effort.
If I sell that tree to a sawmill, they can cut the tree into usable lumber, and sell that lumber at a profit. They added their efforts and increased the value. A carpenter can increase the value even further by making something useful (a door, for example). A retail store can make that door more useful by transporting it to a location with a buyer, and a builder can make it even more useful by installing it on a house.
No one lost any money in any of these transactions. They bought something valuable, and made it more valuable by adding their effort.
Companies in the stock market grow in value the same way. A company will grow in value as its employees produce things. An investor provides capital that the company uses to be able to produce things**, and as the company grows, it increases in value. As the population increases and more workers and customers are born, and as more useful things are invented, the economy will continue to grow as a whole.
* Certainly, it is possible, even common, to profit from someone else's loss. People lose money in the stock market all the time. But it doesn't have to be this way. The stock market goes up, on average, over the long term, and so long term investors can continue to make money in the market even without profiting from others' failures.
** An investor that purchases a share from another investor does not directly provide capital to the company. However, this second investor is rewarding the first investor who did provide capital to the company. This is the reason that the first investor purchased in the first place; without the second investor, the first would have had no reason to invest and provide the capital. Relating it to our tree analogy: Did the builder who installed the door help out the tree farmer? After all, the tree farmer already sold the tree to the sawmill and doesn't care what happens to it after that. However, if the builder had not needed a door, the sawmill would have had no reason to buy the tree.