You are much better off using the built-in WordPress AJAX request.
So, in your functions.php themes, add a function to be called, for example:
function checkUser() { $userid = $_POST['user']; //validation also :) $oMySQL = new MySQL(); $query = "Select * FROM videotable WHERE uid = '$userid'"; $oMySQL->ExecuteSQL($query); $bb = $oMySQL->iRecords; $aa = $oMySQL->aResult; echo $bb; if ($bb == 0){ $query = "INSERT INTO videotable VALUES ('','$userid','true')"; $oMySQL->ExecuteSQL($query); echo 'true'; exit(); } else { $sharing = mysql_result($aa,0,"share"); echo $sharing; exit(); } }
After that, you add your hook using connections to the embedded AJAX system
add_action('wp_ajax_check_user', 'checkUser'); add_action('wp_ajax_nopriv_check_user', 'checkUser');
wp_ajax_nopriv_%s allows it to be called from the front end.
And then, in your javascript file, you just run your ajax request.
$.post(ajaxurl, { action: 'check_user', user: userId }, function(output) { alert(output); });
If ajaxurl is undefined, you will need to create it in the template file, something like this should work, but there are other ways.
add_action('wp_head','ajaxurl'); function ajaxurl() { ?> <script type="text/javascript"> var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>'; </script> <?php }
Backend wordpress does the rest.
It takes the action passed in the AJAX request, looks for the corresponding hook `wp_ajax(_nopriv)_%s , and then calls the function assigned to the hook.
It will also be passed in either $_POST or $_GET depending on the type of AJAX request.
You can read a little more about using AJAX inside Wordpress .