Right now my it shows that the username is available even when the name already exists in my database.
php
session_start();
$conne=mysqli_connect("localhost","username","","my_db");
$name = $_POST['name'];
$check_if_exists="SELECT * FROM names WHERE name = '$name'";
$count = mysql_num_rows($check_if_exists);
if($count != 0) {
$_SESSION['msg']="The name already exists. Please try another name";
} else {
$sql="INSERT INTO names(name) values('$name')";
if ($conn->query($sql) === TRUE) {
$_SESSION['msg']="The name was inserted successfully";
}
}
header("location:form.php");
Somehow it shows that the name is available and it will insert en give the message that the action was succesfull
html
<div class="msg">
<?php if(isset($_SESSION['msg']))
{
echo $_SESSION['msg'];
unset($_SESSION['msg]);
}
?>
</div>
<form action="check_insert.php" method="post">
<input type="text" name="name" id="name" class="form-control" required>
<input class="btn btn-default" type="submit" value="Voeg domein toe!">
</form>