Warning: mdecrypt_generic() [function.mdecrypt-generic]: An empty string was passed in C:\wamp\www\enc\chatting.php on line 46
<p>I am stuck at this code and I don't know what to do next. In this code I am accepting a hex value from POST, decrypting it, and then storing the result in a MySQL database. I am using 128-bit AES for encrypton and decryption.</p>

<blockquote>
  <p>ERROR:Warning: mdecrypt_generic() [function.mdecrypt-generic]: An empty string was passed in C:\wamp\www\enc\chatting.php on line 46
  Error: 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 'dec)VALUES('','')' at line 1</p>
  
  <p>LINE NO:$decrypted = mdecrypt_generic($td, $code);</p>
</blockquote>

<pre><code>&lt;?php

$username = "root";
$password = "";
$hostname = "localhost"; 

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
//echo "Connected to MySQL&lt;br&gt;";

//select a database to work with
$selected = mysql_select_db("akshay",$dbhandle)
or die("Could not select examples");

echo ($_POST['msg']);

class MCrypt
    {
            private $iv = 'fedcba9876543210'; #Same as in JAVA
            private $key = '0123456789abcdef'; #Same as in JAVA


            function __construct()
            {
            }

            protected function hex2bin($hexdata) {
              $bindata = '';

              for ($i = 0; $i &lt; strlen($hexdata); $i += 2) {
                    $bindata .= chr(hexdec(substr($hexdata, $i, 2)));
              }

              return $bindata;
            }

          function decrypt($code) {
              //$key = $this-&gt;hex2bin($key);
              $code = $this-&gt;hex2bin($code);
              $iv = $this-&gt;iv;

              $td = mcrypt_module_open('rijndael-128', '', 'cbc', $iv);

              mcrypt_generic_init($td, $this-&gt;key, $iv);
              $decrypted = mdecrypt_generic($td, $code);

              mcrypt_generic_deinit($td);
              mcrypt_module_close($td);

              return utf8_encode(trim($decrypted));
            }                  
        } 
echo ($_POST['msg']);
        $mcrypt = new MCrypt();
        $decrypted = $mcrypt-&gt;decrypt($_POST['msg']);
        echo($decrypted);

        //execute the SQL query and return records
        $sql="INSERT INTO chat(msg,dec)VALUES('".$_POST['msg']."','$decrypted')";



if (!mysql_query($sql,$dbhandle))
{
    die('Error: ' . mysql_error());
}

mysql_close($dbhandle);

?&gt;
</code></pre>
