What common mistake could lead to an empty result when using mcrypt_encrypt() in PHP, as discussed in the forum thread?

The common mistake that could lead to an empty result when using mcrypt_encrypt() in PHP is not specifying the correct encryption mode and padding. To solve this issue, make sure to use the appropriate encryption mode and padding for your encryption algorithm. For example, if using AES encryption, the recommended mode is CBC and the padding should be PKCS7.

$key = 'your_secret_key';
$data = 'data_to_encrypt';
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_DEV_URANDOM);
$encrypted_data = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $data, MCRYPT_MODE_CBC, $iv);

echo base64_encode($encrypted_data);