This is my first time trying to link an register/login form to an database. I've done some research on how I should do it and kind of followed an tutorial via youtube but I can't make it work.
This is my html code for the form
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-sclae =1.0">
<title>Inregistreaza-te</title>
<script src="https://kit.fontawesome.com/d811942799.js" crossorigin="anonymous"></script>
<link rel="stylesheet" href="./css/register.css">
</head>
<body>
<div class="wrapper">
<h1>Inregistreaza-te</h1>
<form action="insert.php" method="post">
<input type="text" placeholder="Nume de utilizator" name="username" required>
<input type="text" placeholder="Nume" name="nume" required>
<input type="password" placeholder="Parola" name="parola" required>
<input type="password" placeholder="Reintrodu parola" required>
</form>
<div class="terms">
<input type="checkbox" id="checkbox" required>
<label for="checkbox">Sunt de acord cu termenii si conditiile.</label>
</div>
<button type="submit" value="Sumbit">Inregistrare</button>
<div class="member">
Ai deja un cont? <a href="./login.html">
Conecteaza-te
</a>
</div>
</div>
</body>
</html>
This is my php code
<?php
$username = $_POST['username'];
$parola = $_POST['parola'];
$nume = $_POST['nume'];
if (!empty($username) || !empty($parola) || !empty(nume)) {
$host = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbname = "webdesign";
$conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);
if (mysqli_connect_error()){
die('Connect Error('. mysqli_connect_errno().')'. mysqli_connect_error());
} else {
$SELECT = "SELECT username From utilizatori Where username = ? Limit 1";
$INSERT = "INSERT Into utilizatori (username, parola, nume) values(?, ?, ?)";
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($email);
$stmt->store_result();
$rnum = $stms->nume_rows;
if ($rnum==0){
$stmt->close();
$stmt = $conn->prepare($INSERT);
$stmt->bind_param("sss", $username, $parola, $nume);
$stmt->execute();
echo "Utilizator nou inregistrat cu succes!";
} else {
echo "Deja exista un utilizator cu aceasta adresa de mail!";
}
$stmt->close();
$conn->close();
}
} else {
echo "Toate campurile trebuie completate";
die();
}
?>
Sorry in advance for being newbie with my question and have a nice day!
I have checked my code on phpcodechecker.net, initially there was a typing problem, solved id, now I have no error in my code(hopefully).