Is it illegal to provide stock tips on online forums, if you are also investing or have invested in the same stocks?
If you disclose your position (that is, not just that you have interest in the company) there should be no problem. To avoid legal complications you should also state where your authority is from. So if you have, for example, a CFA designation, that might be pertinent to those reading your post. If you have no experience, certifications, or general clout then it would be advisable to disclose this. Here's an example if you have a long position on Tesla and have no certifications:
Pavan is currently long on Tesla and is providing advice based on personal research and is not affiliated with any financial institution or professional designation.
If you do not want to disclose your position or your accumen, you could definitely be in legally murky waters. Because it is stocks, there is inherent risk involved, but if you led someone to believe that you had some qualifications or no personal interest in the company that could be considered "misleading conduct" and depending on the damage/your writing, you could be liable. Would not advise going this route. Glen Pierce in the comments of this answer also makes a valid point:
...don't make misleading statements about the assets themselves (ie: don't claim the company is in different financial circumstances than it really is)
Disclosing everything = No problem
Not disclosing everything = Big problem
Hopefully this helps!