I am trying to encrypt my 'password' column with SHA2. The problem is that the injection to MYSQL is through a $_POST variable, so I don't understand where i should put the SHA2().
Here is my 'insert' page (inscreate.php):
<?php
include 'header.php';
$ins="INSERT INTO users (uname, pwrd, bdate, mail)
VALUES ('$_POST[uname]','$_POST[pwrd]','$_POST[bdate]','$_POST[mail]')";
if (!mysqli_query($con,$ins))
{
die('Error: ' . mysqli_error($con));
}
echo "User added! You will be returned to the index page!";
mysqli_close($con);
?>
From what I have read I have to put it in the 'value' section of my insert query: http://coderlearner.com/MySQL_Encryption-Decryption_Example_SHA2
So I tried these combinations:
$ins="INSERT INTO users (uname, pwrd, bdate, mail)
VALUES ('$_POST[uname]','SHA2($_POST[pwrd])','$_POST[bdate]','$_POST[mail]')";
but then if the password was for example: mypass, the output in my database was this: SHA2(mypass)
I tried this:
$ins="INSERT INTO users (uname, pwrd, bdate, mail)
VALUES ('$_POST[uname]',$_POST[SHA2(pwrd)]','$_POST[bdate]','$_POST[mail]')";
But then I get a Parse error(which I understand why, but still I was just trying) So my question is: Does anyone know how I encrypt a $_POST??