This question already has an answer here:
How to encrypt/decrypt data in php?
When decrypting, you need to use the same IV and key as when encrypting.
Your encrypt function needs to return the IV as well as the encrypted data. That IV should then be sent to the decrypt function along with the data and the key.