I am trying to pass arguments to php script with AJAX. The php script should put the data in a mysql database table. Right now, it is not putting anything in the table, and I don't understand what is wrong.
Here is the ajax script:
<script type="text/javascript">
// jQuery's version of ondomready
$(function(){
$("#up_left").click(function(event){
// Prevents the browser from navigating to the link in the href tag.
event.preventDefault();
//var presets = $("select[name='presets']").val();
//var zoom = $("select[name='zoom']").val();
var movement = $("select[name='movement']").val();
// AJAX (POST)
$.post('http://www.tinyang.net/cam/mupdate.php', {
cmd: 'MOVE-UPLEFT'
,zoom: 'NULL'
,movement: movement
,presets: 'NULL'
});
});
});
</script>
<a id="up_left" href="#" target="return"><img src="up_left.jpg" border="0" width="20" height="20"></a>
Here is the php script:
<?php
// $zoom = $_POST['zoom'];
// $movement = $_POST['movement'];
$cmd = $_POST['cmd'];
$zoom = $_POST['zoom'];
$movement = $_POST['movement'];
$presets = $_POST['presets'];
//Connect and select database
mysql_connect("host", "username", "password") or die(mysql_error());
mysql_select_db("tutorial") or die(mysql_error());
$query="INSERT INTO example (cmd, zoom, movement, presets) VALUES ('".$cmd."', '".$zoom."', '".$movement."', '".$presets."')";
mysql_query($query) or die(mysql_error());
echo "Database updated with: " .$zoom. " ".$movement ;
?>
and here is the url to the webpage this is occuring on:
webpage
What am I doing wrong? Thanks much!