<?php
require 'acdet.php';

$userName = $_POST['userName'];
$userEmail = $_POST['userEmail'];

$response = "";

//Mysql connection test
$mysqli = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);

$userName = $mysqli->real_escape_string($userName);
$userEmail = $mysqli->real_escape_string($userEmail);

/*
// Check connection
if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
} else {
    echo "Connected successfully";
}
*/
$sqlName = "SELECT * FROM accounts WHERE username = '$userName'";
$resultName = $mysqli->query($sqlName);

$sqlEmail = "SELECT * FROM accounts WHERE email = '$userEmail'";
$resultEmail = $mysqli->query($sqlEmail);

if($resultName -> num_rows > 0){
    $response .= "nameUsed";
}

if ($resultEmail -> num_rows > 0) {
   $response .= " emailUsed";
}

$mysqli->close();

echo $response;

?>