Gym, hmm its been a long time. I swim now, better for losing weight. Gym is useful if you want to build bulk.
Don't overdo any exercise. Have a count on your reps and sets, and increase them gradually, meaning over weeks and months, not days.
Don't compete with someone else in the gym, your bodies are different, at the least you'll have a sprain, at worst you'll tear a muscle or ligament. Remember these heal by scarring so you'll lose your original function/power depending on the location or severity of the tear.
Stay hydrated, I used to dissolve a packet of Electral ORS in one litre of water and sip regularly. You can have plain water too in between. Remember while exercising you lose salt. When I say salt people remember the sodium of sodium chloride but forget about the potassium. Low potassium will make you cramp. Electral will take care of both. You might have seen some champion tennis players eating an orange or banana at the breaks. This gives them salts
Work in cycles - one day chest and biceps, one day legs and triceps, one day shoulder and LATS. Don't mix triceps and shoulder as it will strain your muscle. You can do this for six days, and take a complete break on Sunday or any other day of the week. Yes, rest is one of the most important requirements when you go to the gym. It is required to repair damaged muscle and also to allow the muscle to grow. Train for three months, rest for 2-3 weeks, and then start again