It was tricky!!!
You just running query twice (see my remarks)...
$con = mysqli_connect("localhost", "root");
mysqli_select_db($con, "ajaxdatabase");
$first = $_POST["firstname"];
$last = $_POST["lastname"];
$sql1 = "INSERT INTO user(FirstName,LastName)VALUES('$first','$last')";
$query1 = mysqli_query($con, $sql1);
if (!mysqli_query($con, $sql1)) {
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
$sql = "SELECT * FROM user";
$query = mysqli_query($con, $sql);
echo "<table border='1'>
<tr>
<th>Id</th>
<th>FirstName</th>
<th>LastName</th>
</tr>"
while ($result = mysqli_fetch_array($query)) {
echo '<tr>';
echo '<td>' . $result['Id'];
echo '<td>' . $result['FirstName'];
echo '<td>' . $result['LastName'];
echo '</tr>';
}
echo'</table>';
If you want to check that the query went good do this:
if(mysql_affected_rows($conn)!=1) {
die('Error: ' . mysqli_error($con));
}
Or you can drop the line remarked FIRST RUN...