I have a file called functions.js where I have the functiom sum which computes the score that a student takes at a test. I want that sum to be printed into a table in the file admin.php so that the administrator sees all the scores that each student has.
So how can I pass the sum variable to another file? I tried calling the function using the onlick action but that didn’t work
I guess you probably want something like this
This passes the score to a PHP programme
savescore.phpwhen you click a button with idsaveScoreButton. The PHP programme then has to retrieve it using$_GET["score"].Note that this would be easy for the user to trick if they understand javascript and see what is happening. They could just type ‘savescore.php?score=100’ in the browser’s address bar. If you want a secure solution the javascript should only pass the user’s answers to the PHP programme, which would then mark the test and sum the results.
It is also possible to use the POST method instead of GET to pass a value:
Then pick it up in the PHP programme using
$_POST["score"].As mentioned in comments, if you want to compare/tabulate scores, then
savescore.phpwill need to store the values in a database or file so that they can be retrieved byadmin.php.