I would also add, I do not think ajax works the way you think. You can send stuff like an object, string, an array or a JSON. In the code above it is expecting a JSON response. But you are not sending a JSON object.
Also, it will get the result of the first echo, and move on. It would not expect further information, and so will not display it.
So Ajax would look like this:
$.ajax({
url: 'authenticate2.php',
type: 'POST',
dataType: 'HTML',
data: {
username: $('#username').val(),
},
success: function (res) {
$('#resultBox').text(res);
}
});
The PHP would need to look like this:
$con = mysqli_connect('127.0.0.1','root','','db1');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"db1");
$sql="SELECT * FROM Users WHERE userName = '$username'";
$result = mysqli_query($con,$sql);
$dataTable = "<table>
<tr>
<th>userName</th>
<th>userPassword</th>
<th>userEmail</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
$dataTable += "<tr>";
$dataTable += "<td>" . $row['userName'] . "</td>";
$dataTable += "<td>" . $row['userPassword'] . "</td>";
$dataTable += "<td>" . $row['userEmail'] . "</td>";
$dataTable += "</tr>";
}
$dataTable += "</table>";
echo $dataTable;
mysqli_close($con);
?>
Hope this helps 