This is getting really confusing now... Updating a mysql database without leaving the page.... I have 3 bits of code. The javascript in the head tags, the action button in the body and the code to be performed on another page. Here are the three sections:
<script type="text/javascript" src="jquery-1.4.2.js"></script>
<script type="text/javascript">
function addItemToUsersList(itemId)
{
$.ajax({
'url': 'member-bucketadd-exec.php',
'type': 'GET',
'dataType': 'json',
'data': {itemid: itemId},
'success': function(data)
{
if(data.status)
{
if(data.added)
{
$("span#success"+itemId).attr("innerHTML","Item added to your personal list");
alert("Item added to your list!");
}
else
{
$("span#success"+itemId).attr("innerHTML","This item is already on your list");
alert("This item is already on your list!");
}
}
},
beforeSend: function()
{
$("span#success"+itemId).attr("innerHTML","Adding item to your bucketlist...");
}
,'error': function(data)
{
// what happens if the request fails.
$("span#success"+itemId).attr("innerHTML","An error occureed");
alert("On your list!");
}
});
}
</script>
The action button ...
<a onclick="addItemToUsersList(<?php echo $itemid ; ?>)">Add<img src='images/plus-green.png' /> </a>
And the code that is run on the other url...
<?php
ini_set('display_errors', 'On');
error_reporting(E_ALL);
$bucketlist=MYSQL_QUERY( "SELECT * FROM membersbuckets where userid = $userid AND bucketid = $bucketid")
or die(mysql_error());
$bucketlist=mysql_fetch_array($bucketlist) ;
if($bucketlist < 1)
{
mysql_query("INSERT INTO membersbuckets (memberbucketid, userid, bucketid, complete)
VALUES ('', '$userid', '$bucketid', '0')");
return json_encode(array("status" => true, "added" => true));
}
else
{
return json_encode(array("status" => true, "added" => false));
}
?>
It doesn't matter if the item is already on the list (like it is supposed to check bucket<1), or not on the list I always get the alert("On your list!"); , and also the link / the activation button bit, when I hove over it I don't get the hand/finger i just get a text cursor!!
I have never used jquery, or ajax before this little project so have no idea what to look for to see what is out of place. I have downloaded firebug and tested it with that but I can't see any problem/s. Can anyone help?
Thank you anyone and everyone in advance! hope you can help.