<?php 
//first, connect to your database
//make sure you have the users table set up if you're going to test with this exact code.

$key 'ASKSDFNSDFKEISDJAHDLDSDF1235UUUiidfsdf';  //this key should be stored in a file somewhere else on your server

if ($_POST) {
mysql_query("INSERT INTO users (user_first, user_last, user_password) VALUES 

    (
        '"
.$_POST['first']."',
        '"
.$_POST['last']."',
        AES_ENCRYPT('$_POST[password]','$key')
    )
    "
);

//retrieve decrypted password from database
$password mysql_fetch_row(mysql_query("SELECT AES_DECRYPT(user_password,'$key') FROM users WHERE user_id = ".mysql_insert_id().""));
echo 
$password[0];

header('Location: encrypt.php?success'); die;
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>AES_ENCRYPT and AES_DECRYPT</title>
</head>

<body>
<?php
if (isset($_GET['success'])) {
echo 
"<strong>User Added Successfully</strong><br><br>";
}
?>

<form id="form1" name="form1" method="post" action="">
  First Name<br />
  <input name="first" type="text" id="first" />
  <br />
  <br />
  Last Name<br />
  <input name="last" type="text" id="last" />
  <br />
  <br />
  Password<br />
  <input name="password" type="password" id="password" />
  <br />
  <br />
  <input type="submit" name="Submit" value="Submit" />
</form>

</body>
</html>