I am working on a website where you can register. Now am I aware that when handling user input you must use prepared statements.
Now my problem. On this registration form when I try to register the query does not execute but I don't get any errors either. I have tried back ticks in the query, no back ticks. But to no avail(otherwise I would not ask the question:P).
Could someone say if I am using the right way to check if the query was successful or not?
Here is the HTML form:
<form id="register" action="Register.php" name="register" method="post">
<table>
<tr>
<td>
<label id="lblUsername">Username</label>
</td>
<td>
<input type="text" id="txtUsername" name="username" required>
</td>
</tr>
<tr>
<td>
<label id="lblEmail">Email</label>
</td>
<td>
<input type="text" id="txtEmail" name="email" required>
</td>
</tr>
<tr>
<td>
<label ID="lblPass">Password</label>
</td>
<td>
<input type="password" name="password" ID="txtPassword" required>
</td>
</tr>
<tr>
<td>
<label ID="lblConfPass">Herhaal password</label>
</td>
<td>
<input type="password" name="confpass" ID="txtconfpass" required>
</td>
</tr>
<tr>
<td><label id="lblVnaam">Voornaam:</label></td>
<td><input name="vnaam" type="text" required></td>
</tr>
<tr>
<td><label id="lblAnaam">Achternaam:</label></td>
<td><input name="anaam" type="text" required></td>
</tr>
</table>
<input type="submit" name="submit" value="Registreren" required>
<br />
</form>
Here is the PHP part:
error_reporting(E_ALL);
ini_set('display_errors', -1);
if(isset($_POST['submit']))
{
$host = "localhost";
$username = "root";
$password = "password";
$dbname = "mijnwebsite";
$conn = new mysqli($host,$username,$password,$dbname);
if($conn->connect_errno)
{
die('Unable to connect to the database. [' . $conn->connect_error . ']');
}
$errors = array();
$data = array();
$fname = $_POST['vnaam'];
$lname = $_POST['anaam'];
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$confpass = $_POST['confpass'];
$password_hash = crypt($password);
$stmt = $conn->prepare("INSERT INTO `User`(`Fname`, `Lname`, `Email`, `Username`, `Password`) VALUES(?,?,?,?,?)");
$stmt->bind_param("sssss", $fname, $lname, $email, $username, $password_hash);
if(!$stmt->execute())
{
die("Kon query niet uitvoeren. " . $stmt->error);
}
else
{
echo '<script type="text/javascript">alert ("Registratie gelukt! klik op oke om door te gaan.");</script>';
}
}
?>
Note: I am going to validate the input but right now I just want to be able to insert.
Thank you guys in advance. Also if there are things that need to be added please leave a comment.
Edit: I have changed the error reporting. That was the reason I didn't got any errors back. The Error i got back was:
Fatal error: Call to undefined function password_hash() in /var/www/Register.php on line 140
Edit 2 : As per Fred -ii- Answer here by i will post my DB structure 
Edit 3: now that i added the back tick to the end of Username when preparing the query and i added this if(!$stmt->execute()){trigger_error("There was an error....".$conn->error, E_USER_WARNING);} I get a different error.
Fatal error: Call to a member function bind_param() on a non-object in /var/www/Register.php on line 146
Note 4: I have updated the code to match the Answer of @Fred-ii- and what is working right now. I want to Thank everybody who has taken time out of their day to help me out.
error_reporting(-1);,mysqli_errorandmysqli_stmt_errordisplay_errortodisplay_errors.