I have some code that I have gone over at least 30 times by now, and it has plagued me for months (really). I have fixed as many errors as I see, but it simply doesn't work. I hope that any reader of this can find my mistake...
Ok, so the code is simply an ajax request on a mouseover effect that posts data to another page, in which the data is received. Please take a look:
Here is the ajax request:
$(document).ready(function () {
$("#secretcoin").mouseover(function () {
$.ajax({
type: "POST",
url: "achievements.php",
data: {
Home_Coin_Locator: "Yes"
},
error: errorAlert
});
});
});
So that is the request - and now here is the receiving page, achievements.php
$achieve4 = $_POST['Home_Coin_Locator'];
if ($achieve4 == 'Yes') {
$awardSTRsql = "UPDATE Awards_Inv SET Home_Coin_Locator='Yes' WHERE Username = '$username'";
mysql_query($awardSTRsql, $connection) or die(mysql_error());
$updatestatsSTRsql = "UPDATE User_Info SET Coins = Coins + 120, Skill_Points = Skill_Points + 10, Awards = Awards + 1 WHERE Username = '$username'";
mysql_query($updatestatsSTRsql, $connection) or die(mysql_error());
} else {}
I have reduced my code to small amounts, and checked it vigorously, but it still doesn't work...
by the way, $connection is simply my connection to the database, which I can guarantee is accurate. $username is the session username that is defined in code that I didn't provide, but I also know that the variable is accurate...
Please help me!
The javascript seems to be correct to test the php file easier you should do this:
> $achieve4 = $_GET['Home_Coin_Locator']; if ($achieve4 == 'Yes') {
> $awardSTRsql = "UPDATE Awards_Inv SET Home_Coin_Locator='Yes' WHERE Username = '$username'";
> mysql_query($awardSTRsql, $connection) or die(mysql_error());
> $updatestatsSTRsql = "UPDATE User_Info SET Coins = Coins + 120, Skill_Points = Skill_Points + 10, Awards = Awards + 1 WHERE Username =
> '$username'";
> mysql_query($updatestatsSTRsql, $connection) or die(mysql_error()); } else {}
then go to /achievements.php?Home_Coin_Locator=Yes and see if there is any error.
Make sure you php error reporting is on so if there are any errors they will be displayed.