Last fall I did the imaginable. Something you hear happens to others, but never think will happen to you. I was in the bathroom and I placed my iPhone on some towels conveniently located adjacent to the toilet. The phone slid off and performed a swan dive into the toilet. If you are reading this, I guess you can relate as this has probably just happened to you. Don't worry; If you follow a few guidelines, your phone should be fine.
Water is destructive to electronics, but the initial risk is greatly reduced if you can power off the device and take out the battery. Unfortunately, the iPhone doesn't alow us to take out the battery. The next best thing is to power the phone down. To turn it off, hold down the 'sleep/wake' button (it's the button on the top right corner) untill the power-down screen appears. Move the slider to the right to confirm powering the phone down. Don't be suprised if your iPhone becomes warm even turned off. The battery may be shorted out and if this is the case, it will generate heat until it is fully discharged.
Water can get trapped between the protective case (if you use one) and the phone so go ahead and strip that off. Next, get a towel and dry off the outside of the phone taking care to get water away from the side switches and the dock connector and speakers at the bottom.
This is where the magic happens to bring your iPhone back from the dead. It's a step that shouldn't be rushed and can't be skipped. You need a plastic snadwitch bag that seals airtight. You also need a material that will abosorb moisture, such as a dessicant. Dessicant material absorbs moisture and it is just the ticket to absorb the moisture that evaporates from inside your wet iPhone. Dessicant packages are available online. They come with many products you purchase and say "Silica Gel" on them. I save them anytime I come across one and store them in an airtight plastic bag.
If you don't have packages of dessicant, you can use rice, or you can use a combinaiton of both. I'm talking UNCOOKED rice. Place the dessicant packages and/or the rice in the plastic zip-lock bag. Then place your flooded iPhone in the bag and seal it up. Don't be suprised if your iPhone becomes warm even turned off. The battery may be shorted out and if this is the case, it will generate heat until it is fully discharged.
Being sealed, the dessicant will absorb any moisture in the air and trap it. The air will continually be dried and the lowered relative humidity will suck all the moisture out of your phone.
Do not power your phone on until the desicant or rice has had time to get the moisture out of the iPhone. To speed things along, you can heat the bag up. Putting the whole bag in a hot car, or on a hot windowsill, helps to speed evaporation from inside the phone. I have also used a hair dryer to heat the bag and the contents to get it dried out sooner. You need to allow at least 12 hours and maybe more before you remove the phone and try to power it on.
When you are brave enough to turn it on, don't be suprised if there is no response. It probably has become fully discharged after being shorted out. First plug it in to give it a charge for an hour. Then, try powering it on.
Odds are if you follow all these steps, you will have a great chance of having the iPhone recover and be functional again.