Score counter using PHP and JavaScript
<p>If I want to add a score counter to my website. for example if the user answers a question then it will be saved in a database and the correct answer is already saved in the same database table. I want to make a comparison  between the answers. if the answer is correct the score raises. </p>

<p>I am planning to code the score counter by using JAVASCRIPT. How can I call the javascript function within PHP.</p>

<p>If I do like that:</p>

<pre><code>&lt;?php
if($_SESSION['Correct_answer'] == $_SESSION['User_answer'])
echo "&lt;SCRIPT LANGUAGE='javascript'&gt;" echo count() "&lt;/SCRIPT&gt;";
</code></pre>

<p>And the javascript function looks like:</p>

<pre><code>&lt;script&gt;
var x=0;
function count(){
x+=1;
document.getElementById( "counting" ).value =  x;
}
</code></pre>

<p>Where "counting" is a text field.
When I tried to use this code it didn't work. Is the above code correct???</p>

<p>Thank you in advance.</p>

<p>Edited:</p>

<p>Ok I did what u said but i still have a problem when refreshing the page the score increases by one. How can I stop the increasing of score when reloading the page???</p>

<p>Here is my code:</p>

<pre><code>if (!isset($_SESSION['score']))
   $_SESSION['score'] = 0;


else{
$sql10=mysql_query("select * from image WHERE fromUser='".$_SESSION['email']."' order by id desc");
$score1=mysql_fetch_array($sql10);
$answer=$score1['answer'];

$sql13=mysql_query("select * from image WHERE toUser='".$_SESSION['email']."' order by id desc");
$score2=mysql_fetch_array($sql13);
$answer2=$score2['answer2'];


strcasecmp($answer,$answer2);
if(strcasemp)
$_SESSION['score'] += 1;
}
</code></pre>
