I have a PHP file run.php that is being used to display content, as well as insert / grab data from a MySQL database.
Within that file is a few JavaScript Promise functions that calculate a result, and display it on the page.
.then(function(calc) {
.... // various calculations
result = 10; // 10 is then displayed on the page
}
The function will end with a single result, for example result = 10
as shown above. That result (10
) is displayed on the page. The issue I have is that I need to pass that result 10
from the JavaScript Promise function into my database.
After researching I'm not entirely sure this is possible. The converting the value from JavaScript to PHP, then inserting into a database seems possible, but I'm not so sure it's possible to actually get the result (10
in this case) from that JavaScript function, because Promises are asynchronus and results can't be returned from them (?).
I was wondering whether there's any way to use PHP to grab the result directly from the page (as the result is displayed on the page, as mentioned), then insert it into my database.
Hopefully someone can shed light on whether this is actually possible.