title: How do I use AES_Decrypt
body: <p>I know this question has been asked a billion times as I've spent the last 2 weeks looking at all the previously asked questions and answers
  but none of them actually have an understandable answer. So my question is this, I have a form that I'm passing the data input by users into a mysql
  database and a portion of that data is encrypted with AES_Encrypt. When I check the database I can see the data has been encrypted so I'm good on the encryption part.
  My issue lies in the decryption part. I've tried multiple variations from previous questions asked with no success, This is what I have so far,</p>
  
  <pre><code>//ENCRYPTING DATA
  require 'path to key.php';
  
  $sql = "INSERT INTO applications "(fname, lname, dob, ssn) VALUES  ('$fname', '$lname', '$dob', AES_ENCRYPT('$ssn', '".$aeskey."')";
  </code></pre>
  
  <p>The code above works fine to encrypt the string.</p>
  
  <p>This is where I'm confused, I'm wanting to select all the data associated with the ID for a record and decrypt the encrypted data for that record as well,
  for example I have a search form that pulls up all the records in the database, you can then select to view a record and the results display in a form similar to the form used
  to input the information. </p>
  
  <p>So in my form to view records I have the following code.</p>
  
  <pre><code>//DECRYPT DATA
  
  require 'path to key.php';
  
  $conn = new mysqli($servername, $username, $password, $dbname);  
  
  
  $data = "SELECT * FROM $tbl_name where ID = $id";
  
  $query = mysqli_query($conn, $data);
  
  $data2 = mysqli_fetch_array($query);
  
  &lt;input type = "text" name="fname" value="&lt;?php echo $data2['fname']?&gt;"/&gt;
  &lt;input type = "text" name="lname" value="&lt;?php echo $data2['lname']?&gt;"/&gt;
  &lt;input type = "text" name="dob"   value="&lt;?php echo $data2['dob']?&gt;"/&gt;
  &lt;input type = "text" name="ssn"   value="&lt;?php echo $data2['ssn']?&gt;"/&gt;&lt;-----This will display the encrypted data in the encrypted form 
  </code></pre>
  
  <p>So do I need to decrypt the encrypted data from the input box like </p>
  
  <pre><code> &lt;input type = "text" name="ssn" value=&lt;?php echo [AES_DECRYPT('ssn', '$aeskey')]?&gt;"/&gt; &lt;---Doesn't work
  </code></pre>
  
  <p>or do I need to do something like this:</p>
  
  <pre><code>$sql SELECT * FROM $tbl_name (AES_DECRYPT('ssn', '$aeskey')) WHERE ID=$id;
  </code></pre>
  
  <p>Or am I totally wrong in how I think AES_DECRYPT should be used?  </p>