Search code examples
javascriptphphtmlsqlxmlhttprequest

Having trouble with SQL MAX()


Here is my code.

$sql2 = 'SELECT MAX(ASSIGNMENT_ID) FROM assignments';
$result2= mysqli_query($connection,$sql2);
$row2= $result2->fetch_assoc();
$assignment_id=$row2['assignment_ID'];

That is the best I have gotten it after many different iterations. I cannot debug this using the xhr.response because I keep getting"XHR failed loading: POST" console messages despite everything posting fine to my SQL database. Apparently that XHR error causes me not to get back any php messages back at all. This problem as a whole I've been stuck on for several hours- any help I would be very appreciative of.


Solution

  • $sql2 = 'SELECT MAX(ASSIGNMENT_ID) as assignment_ID  FROM assignments';
    

    Than use your key $row2['assignment_ID']