here is my process.php file
$username = $_POST['name'];
$password = $_POST['password'];
if(!empty($username) || !empty($password)){
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "tut";
//connection
$conn = new mysqli($servername, $username, $password, $dbname);
if(mysqli_connect_error()){
die ('connect Error('. mysqli_connect_error().')'. mysqli_connect_error());
}else {
$SELECT = "SELECT username From register Where username = ? Limit 1";
$INSERT = "INSERT Into register (username, password) values(?, ?)";
}
//prepare statement
$stmt = $conn->prepare($SELECT);
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->bind_result($username);
$stmt->store_result();
$rnum = $stmt->num_rows;
if ($rnum==0){
$stmt->close();
$stmt = $conn->prepare($INSERT);
$stmt->bind_param("ss", $username, $password);
$stmt->execute();
echo "New record inserted succesfully";
}else{
echo "someone has already used this username";
}
$stmt->close();
$conn->close();
}else{
echo "All fields are required";
die();
}
and here is my index.php
<?php
require "header.php"
?>
<button action="process.php" method="POST">
Klicka för att lägga in en produkt
</button>
<form action="process.php" method="POST">
<input type="text" name="name" placeholder="name">
<input type="password" name="password" placeholder="password">
<input type="submit">
</form>
<?php
require "footer.php"
?>