City walls don't seem to protect cities against barbarian attacks. It is a problem for the AI as well. When the barbarians attack it takes away a whole city regardless of if it has a wall around it or not.
City wall helps you to store more resource cards on hand - read rules.
Only thing that stops barbarians except knights is citadel (level 4 upgrade of any kind) but that also protects just one city so if you have two out of which only one is citadel barbarians will invade other one if not protected.
But really read rules before playing please!