Is it a good idea to use Javascript to create an account or is it prone to security risks? If it's fine, I need to be able to display some errors if the username or email address already exists. 

e.g.

Javascript:

```
function createAccount() {
   var new_user = $('#new-username').val();
   var new_pass = $('#new-password').val();
   var confirm_pass = $('#confirm-password').val();
   var new_email = $('#new-email').val();
   $.post('createaccount.php', {
       new_user: new_user,
       new_pass: new_pass,
       confirm_pass: confirm_pass,
       new_email: new_email
   });
}

```

createaccount.php:

```
$new_username = mysqli_real_escape_string($conn,$_POST['new_user']);
$new_password = mysqli_real_escape_string($conn,$_POST['new_pass']);
$new_email = mysqli_real_escape_string($conn,$_POST['new_email']);
$confirm_password = mysqli_real_escape_string($conn,$_POST['confirm_pass']);

$query = mysqli_query($conn,"SELECT * FROM users WHERE username='$new_username'");
$numrows = mysqli_num_rows($query);
$query2 = mysqli_query($conn,"SELECT * FROM users WHERE email='$new_email'");
$numrows2 = mysqli_num_rows($query2);

...

echo json_encode(array('numrows'=>$numrows,'numrows2'=>$numrows2));

```

I need to be able to use `numrows` and `numrows2` somehow with $.getJSON to alert some errors (like the username already exists, or the email address is already in use). Any way to do this?