I'm busy creating a login system for my site and now I'm focusing on the registering system but I read that the POST method is vulnerable to SQL-injection and I want to change that. Now my problem is that I don't know very much about PHP and I don't get how to use prepared statements. Can anyone help me implementing it? Here is my code:
<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
include('connect.php');
// If the values are posted, insert them into the database.
if (isset($_POST["username"]) && isset($_POST["password"])){
    $username = $_POST["username"];
    $email = $_POST["email"];
    $password = $_POST["password"];
    $epassword = hash("sha512", $password);
    $query = "INSERT INTO `user` (username, password, email) VALUES ('$username', '$epassword', '$email')";
    $result = mysqli_query($connection, $query);
    if($result){
        $msg = "User Created Successfully.";
    }
}
?>
<!DOCTYPE html>
<html>
<body>
<div id="wrapper">
<head>
<title>Franeker Computer Reparaties</title>
<link rel="stylesheet" href="styles.css" />
</head>
<h1 id=logo>
<a href=""> </a>
</h1>
<div class="register-form">
<?php
if(isset($msg) && !empty($msg)){
    echo $msg;
    }
 ?>
<h1>Registreer</h1>
<form action="" method="POST">
<p><label>User Name : </label>
<input id="username" type="text" name="username" placeholder="username" /></p>
<p><label>E-Mail       : </label>
 <input id="password" type="email" name="email" required placeholder="name@email.com" /></p>
 <p><label>Password   : </label>
 <input id="password" type="password" name="password" placeholder="password" /></p>
<a class="btn" href="login.php">Login</a>
<input class="btn register" type="submit" name="submit" value="Registreer" />
</form>
</div>
<div id="navwrapper">
  <ul id="nav">
    <li><a href="index.php">Home</a></li>
    <li><a href="diensten.php">Diensten</a></li>
    <li><a href="advies.php">Advies</a></li>
    <li><a href="contact.php">Contact</a></li>
  </ul>
</div>
</div>
</body>
</html>
 
     
    