Yes, the price of a stock is what investors think the value of a stock is, which is not tied to profits or dividends by any rigid formula. But to say that therefore the price could be high even though the company is doing very poorly is hypothetically true, but unlikely in practice.
Consider any other product. There is no fixed formula for the value of a used car, either. If everyone agreed that a rusting, 20-year old car that doesn't run is worth $100,000, then that's what it would sell for. But that's a pretty big "if" at the beginning of that sentence.
If the car had been used in some hit TV show 20 years ago, or if it was owned by a celebrity, or some such special case, maybe a rusting old car really would sell for $100,000. Likewise, a stock might have a price higher than what one would predict from its dividends if some rich person wanted to buy that company because the brand name brings back nostalgic memories from his youth and so he drives the price up, etc.
But the normal case is that, in the long term, the price of a stock tends to settle on a value proportional to the dividends that it pays. Or rather, and this is a big caveat, the dividends that investors expect it to pay in the future. And then adjusted for all sorts of other factors and special situations, like the value of the company if it was to be liquidated, etc.