My task is to calculate the number of time each word is dragged into the wrong box and then store it into mysql database ,i used jquery drag and drop ,each time word is dragged into the box the jquery ftn sends the word id,and category to the next page by using ajax post,if the word id and user anme exsit it updates the word dragged else it insert new record.my this code works fine for jst single new insertion and then uodates it too bt it doesnt work for new insertion kindly chk whats wrong with it :
<?php
session_start();
error_reporting(7);
require("db.php");
$Cat=$_POST['Cat'];
$WID=$_POST['Wid'];
$S_qry="Select Wrong_Drag from user_count where W_ID='".$WID."' and User_ID='".$_SESSION['UID']."'";
$R_qry=mysql_query($S_qry);
$num=mysql_num_rows($R_qry);
if ($num == 0)
{
$qry="Insert into user_count (User_ID,W_ID,Wrong_Drag) Values('".$_SESSION['UID']."','".$WID."','1')";
$Result=mysql_query($qry);
}
else
{
while(mysql_fetch_assoc($R_qry))
{
$sql = "Update user_count set Wrong_Drag=Wrong_Drag+1 Where W_ID='".$WID."' and User_ID ='".$_SESSION['UID']."' ";
$query = mysql_query($sql);
}
}
?>`