trying to encrypt a social security number and the query works occassionally but once every 5 to 10 times it will throw an in

```
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '�9~���d�~/C�yK�~�� _', ' 50', '62' )' at line 1
SSN: _mosPEdaXEsB7zJCQe5aymaCmkcSl9bnPL5ClLXcz2QA=_ 
IV: _ �6�k���_O�'�9~���d�~/C�yK�~�� _

```

And here's the code

```
    //Encryption/Decryption key
     $Key = hash("SHA256", $Lname, true);
    //Encryption Algorithm
    $cipher_alg = MCRYPT_RIJNDAEL_256;

    $iv =  mcrypt_create_iv(mcrypt_get_iv_size($cipher_alg, MCRYPT_MODE_ECB), MCRYPT_RAND);

    $ESSN = mcrypt_encrypt($cipher_alg, $Key, $SSN, MCRYPT_MODE_CBC, $iv);
    $ESSN = '_' . base64_encode($ESSN) . '_';
     $iv = '_' . $iv . '_';

if(!mysqli_query($connection, "CALL Update_ClientSSN('$ESSN','$iv', ' $AppID',  '" . $_SESSION['ID'] . "' );")){
        $Save .= " Error saving Client SSN";
    echo $connection->error;
    echo $ESSN . ' IV: ' . $iv;
    }

```

also originally I was just concatenating the IV and cipher text then exploding, but that still threw errors so the underscores are just me experimenting. I'm stumped