<?php

include("config.php");
$username =$_POST['username'] ;
$sqlquery ="select * from users where username = '$username'";
$results = mysqli_query($mysql_connection, $sqlquery);
$mysqlnumrows=mysqli_num_rows($results);
if ($mysqlnumrows==0){ $inserttousers="insert into users set 
        role = 'user',
        name=' ".$_POST['name']."',
        email='".$_POST['email']."',
        username='".$_POST['username']." ',
        password='".$_POST['password']."'
";
$insert =mysqli_query( $mysql_connection, $inserttousers)or die('Το ερώτημα προς τη βάση απέτυχε!');

    $message = "Καταχωρηθήκατε επιτυχώς";
    echo "<script type='text/javascript'>alert('$message');</script>";
    echo "<script type='text/javascript'>setTimeout(function() { window.location.href = 'index.php#login<?php echo $uniqueId; ?>'; }, 10);</script>";


}else{
    $message = "Το username είναι ήδη καταχωρημένο";
    echo "<script type='text/javascript'>alert('$message');</script>";
    echo "<script type='text/javascript'>setTimeout(function() { window.location.href = 'index.php#login<?php echo $uniqueId; ?>'; }, 10);</script>";

}
?>