I want to encrypt password in php by use md5 function and I have got an error.
Fatal error: Uncaught Error: Using $this when not in object context in ....(line)
This code I follow up from this link but it was error. I tried to search the similar question on stackoverflow but I doesn't found the same case as me. This is my code. Anyone can help me, please?
The line that found error. $this->stmt = $this->pdo->prepare($sql);
This is my code
<?php
require_once('connect01.php');
function addUser($name, $password){
$hash = md5($password);
$sql = "INSERT INTO `user` (`username`, `pass`) VALUES ('$name','$password')";
$this->stmt = $this->pdo->prepare($sql);
return $this->stmt->execute([$name, $hash]);
}
if(isset($_POST['submit'])){
addUser($_POST['username'], $_POST['pass']);
}
?>