Why can't I connect to the internet on my iPhone 4?
No - you only need a correctly provisioned data plan and working iPhone software. There isn't much that you can mis-configure unless you jailbreak or start mucking with custom iPhone carrier settings profiles. 

iPhone data can break or be misconfigured on the carrier end - even if SMS and voice calls work, there can still be a problem with the data service so you may need to get help from your carrier that is providing your data access. It could also be a software issue and Apple is the best place to get that sorted.

Your question is basically how do I systematically troubleshoot iPhone data and/or teach myself how to operate my new phone. (no offense, but it's hard to determine from a one sentence question what your level of comfort is with iPhone data terms and how it may break.)

You might want to get some help from Apple or the carrier since the internet works as long as you are in working Wifi or your data plan is active on the iPhone. Troubleshooting an issue by back and forth on a discussion board is very hard so it's best to get real-time assistance when you are sitting in front of your computer to update the software if needed.

http://www.apple.com/support/iphone/ has some great getting started tips if you want to work through it yourself.

Specifically http://support.apple.com/kb/HT1976 documents the concepts and has an express lane link to get support directly from Apple to narrow down the cause - if 3G is showing in the menu bar it's not some obvious error or switch but something obscure or a carrier issue.