Reputation: 115
I am inserting the values into the database but i need the password to be encrypted and then insert the special characters to it. I am using mysql database and coding is done in normal php program.
PHP PROGRAM
$mysecretkey = 'd5k8b6q3';
$password=(AES_ENCRYPT('$v4','$mysecretkey')); // problem is here in encryption
$q="insert into customers (name,username,email,password) values('$v1','$v2','$v3','$password')";
$s= mysql_query($q);
if(!$s)
{
$r["re"]="Inserting problem in database";
print(json_encode($r));
}
else
{
$r["re"]="Record inserted successfully";
}
But when i execute the code instead of encrypting it i am getting error
Fatal error: Call to undefined function AES_ENCRYPT() in ..../checking.php on line 5
how to solve this problem and other details is the password field in the database is varchar and i am fetching the data from POST variable v1,v2,v3,v4 and test key is added in the above code.
when i give the password as "test123"
after AES encryption the data has to insert is this "÷A5jèŸ2A1::h "
Thanks for your help and time friends........ Please tell how to solve this issue
Upvotes: 0
Views: 1351
Reputation: 201
You can try more similar to your approach like
mysql_query("SET @password = AES_ENCRYPT('".$v4."','".$mysecretkey."')");
$q="insert into customers (name,username,email,password) values('$v1','$v2','$v3',@password)";
Upvotes: 0
Reputation: 13728
try like below (i think it's a mysql function not php so use direct in query)
$q="insert into customers (name,username,email,password) values('$v1','$v2','$v3',AES_ENCRYPT('".$v4."','".$mysecretkey."'))";
or
$q="insert into customers (name,username,email,password) values('$v1','$v2','$v3',AES_ENCRYPT('$v4','$mysecretkey'))";
for more :- http://www.w3resource.com/mysql/encryption-and-compression-functions/aes_encrypt%28%29.php
Upvotes: 2