First of all, let us try to clarify what both gas and gasPrice is.
If you want to execute something on the Ethereum Virtual Machine (EVM), such as a transaction, gas is needed for the computation. More precisely, every operation has a well-defined amount of gas it uses. Hence, for a transaction, the gas that is needed is equal to the sum over the gas needed for each EVM operation. You can specify an upper limit on how much gas a transaction should require maximally. If you are interested in learning more, you can check yellowpaper.io, where all of this is discussed in more detail. Note that creating (or deploying) a Smart Contract costs gas as well, because you are invoking the constructor and are storing all the code on the Blockchain.
One might ask, why is there such as thing as gas in the first place though? Well, if your contract would, for example, contain
function infiniteLoop() public {
while (true) {
// do some stuff
}
}
a transaction calling infiniteLoop()
would never finish and miners would be executing infinitely. The idea of gas is to prevent just that: If there is only so much gas that can be used, execution has to stop at some point. You can use the Solidity compiler solc to get an estimate of how much gas a function will use. The same can be done online using remix.ethereum.org (Compile the contract and click the constructor to get an estimate of the deployment gas costs).
Now to the gasPrice. Imagine, gas wouldn't cost anything. You could then, theoretically, write a contract doing useless, but intense work and set an unreasonable gas limit. Moreover, why would miners even be willing to execute the transaction on your behalf? The gasPrice, which indicates what you are willing to pay per amount of gas, thus incentivises the miners in the network to execute your transaction and add it to a block.
Having not seen your contract, I can only make a guess what has gone wrong. It could be that indeed you have specified a gas limit that wasn't high enough.