Recently I build a login-system using php and a mysql-database. I entered all users manually so what I want to do next is builging a register-funktion. For some reason however the data don´t land in my database.
This is my register-page:
<div class="login">
<div class="background">
<img src="../pic/skyscrapers.jpg"></img>
<div class="logbox">
<form class="form-register" action="../func/func_register3.php" method="POST">
<h1>Registrierung</h1>
<div class="user">
Choose your username:<br>
<label for="frm_user">username</label>
<input type="text" name="frm_user" id="frm_user" placeholder="Benutzername" required autofocus>
<br>
<br>
Choose your password:<br>
<label for="frm_pass">Password</label>
<input type="password" name="frm_pass" id="frm_pass" placeholder="Password" required>
<br>
<br>
Repeat your password:<br>
<label for="frm_pass_rep">Repetition</label>
<input type="password" name="frm_pass_rep" placeholder="Password"><br>
<br>
<br>
</div>
<button name="btn_register" id="btn_register" type="submit">register</button>
</form>
</div>
</div>
</div>
And this the php-file with the register-logic:
<?php
if (isset($_POST['btn_register'])) {
include("../inc/db_connect.php");
//Form fields -> php-variables
$frm_user = $_POST['frm_user'];
$frm_pass = $_POST['frm_pass'];
$frm_pass_rep = $_POST['frm_pass_rep'];
$stmt = $dbh->prepare("INSERT INTO tbl_users (username, password) VALUES (:frm_user, :frm_pass)");
$stmt->bindParam(':frm_user', $frm_user);
$stmt->bindParam(':frm_pass', $frm_pass);
if ($stmt->execute() == true):
echo "All good!";
else:
{
echo "The statement has not been executed!";
echo "<br>";
echo print_r($stmt->errorInfo, true);
echo "<br>";
echo $stmt->errorCode();
}
endif;
}
The output is "The statement has not been executed! 23000" which is true, there is no data coming through to the database... I already tried using different kinds of browsers and using anonther database. The login works perfektly fine and both files, the one with the login-logik as well as the one with the register-logik, use the same file to connect to the database. I´d be very thankful for all kinds of ideas on how to fix this.