3

I am trying to send Javascript variables over to a PHP script for updating scores of a quiz game. I've looked up the shorthand method of doing this, which is $.post, but I am unable to retrieve the values in the PHP script. I am fairly unfamiliar which JS and require help as to what I am doing wrong.

Here is the Javascript

function updatescore(){ var thisgamemarks= 2300; var thequizid = 5; $.post("updatemark.php", { quizidvalue: thequizid, newmarkvalue: thisgamemarks } ); } 

And the PHP

$studentnewmark = $POST['newmarkvalue']; $thisquizid = $POST['quizidvalue']; $thisstudentid = $_SESSION['studentid']; 
4
  • 1
    what errors do you get, if any, in the javascript console? Commented Mar 16, 2013 at 18:11
  • Off the top of my head: maybe $.post doesn't send stuff as request parameters, but serialised as JSON in the request body. Maybe there's a way to dump the whole request in PHP? Commented Mar 16, 2013 at 18:11
  • try print_r ( $_POST ) on php side, debug it in browser console Commented Mar 16, 2013 at 18:15
  • So far found no errors on the console Commented Mar 16, 2013 at 18:20

2 Answers 2

8

type $_POST instead of $POST. also, on a windows based machine, you can use ctrl + shift + j to debug a js script - which will help if if there's any problems with your code. but, the js code you have shown us looks perfectly fine.

Sign up to request clarification or add additional context in comments.

Comments

0

Yes. As suggest use the $_POST instead of $POST and try putting the "quizidvalue" in the javascript inside quotations. It might help. Just a thought. It's how I always do it.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.