The newNet.php
runs and correctly creates the new entry. The netID
variable is an auto increment so it is created automatically. My goal is to then retrieve it and use it in the showActivities()
function to display the record just created. For example it should resolve like this; showActivities(55)
;
The problem is the SQL always returns the previous value of netID
, 54
instead of 55
; If I say echo $result + 1
; Then, according to page source it shows the correct number is being resolved in the showActivities
function but the function can't find and return the data. But looking at the DB it has successfully been inserted.
So step by step:
newNet.php
runs, it adds a record to a MySQL db- get the
netID
value just created in #1 - pass it to
showActivities()
which displays it on the page.
How can I get what I want here? It would seem that the DB does not get updated fast enough to accommodate the request from showActivities()
, is this possible?
function newNet(str) {
str = str;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState === 4 && xmlhttp.status === 200) {
document.getElementById("status").innerHTML = xmlhttp.responseText;
}}
xmlhttp.open("POST", "newNet.php", true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("q="+str);
showActivities(<?php $stmt=$db_found->prepare("select max(netID) as netID from netLog limit 1");
$stmt->execute();
$result=$stmt->fetchColumn();
echo $result;
?>);
}