If you just want to be friends, tell her what you think, what you feel... Even if it's just "I don't know what to say, I'm so sorry I can't help you but if you want to talk more about it I'm always here for you..."
If it's someone you're trying to pick up, just tell her what she wants to hear... If it's some situation that's upsetting her then ask more details about the situation and what she thinks/feel about it, and agree with her point of view 100% (unless it's something really stupid in which case put your foot down.) And if it's something really bad/serious like family stuff just yeah, like other people say, be there, physical contact is good if possible, say reassuring things...
It's pretty simple really. Most people when they are in a bad/sad mood will look for solitude sooner rather than later anyways, so try not to get in a deep conversation...
As for helping them, it really depends on what their problem is. If it's a depressed/suicide/self-harm problem, contact an anonymous phone service and ask for advice on what to do. Even if they suggest you don't do anything, otherwise you may have some guilt if something happens... If it's a "life" problem like a death in the family, then time will heal all wounds... If it's just some stupid stuff like they spilt coffee on their dress and people laughed at them, then don't worry about it... She'll forget in a couple days. For a lot of things, just being there will be help enough...