This is a difficult question to answer. How do we reconcile the idea that our prayers influence God as James 5:16 implies, yet God knows all things as 1 John 3:20 says?
James 5:16, "Therefore, confess your sins to one another, and pray for one another, so that you may be healed. The effective prayer of a righteous man can accomplish much."
How is it possible for us to influence God who has always known all things from eternity? Does God interact with us in some sense of knowing what we will do and decide to do things in response? Or, does God decree whatsoever shall come to pass including our prayers so that all our prayers are ultimately within His will? The debate within Christianity is deep. However, Scripture is clear. We know that God works "all things after the counsel of his will" (Ephesians 1:11). This means that He includes our prayers in the counsel of His will--from all eternity. But, does God look into the future to see what we are going to pray and then decide what to do based on that? This can't be because it would violate the sovereignty of God who does not react to man's desires and offer "a backup plan" when He "changes His mind." Furthermore, looking into the future to see what would happen would imply that God was learning, which contradicts 1 John 3:20 that says God knows all things. Furthermore, our prayers come from our hearts, and the Bible tells us that God "moves the heart of the king where He wishes to go," (Proverbs 21:1).
On the other hand, James 5:16 says that our prayers can accomplish much. So, we have to ask how our requests to God can accomplish anything if God not only knows what we are going to pray but also has ordained our prayers from the foundation of the world (Eph. 1:11)? The simple answer is that it is beyond our ability to comprehend. The Bible does not tell us how our interaction with God works, but it does tell us God hears our prayers when we pray according to His will (1 John 5:14). Such is the paradox in which we find ourselves.
Paradoxes occur only when there are absolutes. It is absolutely true that God knows all things and has ordained whatsoever shall come to pass (but this does not mean that He causes people to sin). It is also true that God desires that we pray. So how do our prayers influence God when He has ordained those very prayers to occur? Again, we don't know.
It would seem, however, that we "influence" God when we are in His will. In other words, if we are walking in the will of God and we ask God for something in prayer, then we are more likely to receive an answer because we are doing what He wants. In contrast, if we are out of the will of God and we ask Him for something, He will not give it since it is not in His will. So, if we are walking in the will of God and we pray, we are praying according to His will, and our prayers are answered in the affirmative. However, if we are not in His will, they're not answered in the affirmative. Therefore, the issue isn't if God answers our prayers because He does. The issue is whether or not our prayers, and ourselves, are abiding in God's will so that our prayers will be answered.
We are the ones who need to have our wills changed according to His desires--not His will changed according to our prayers.