I am wondering if it is possible to update a database with a hyperlink. On my website, I am attempting to update the user's location in the game world. The locations are represented by numerical values.
Ex:
1 = Camp
2 = Town
3 = Forest
To do so, I created a PHP function:
function updatePlayerLocation($location)
{
mysql_query("UPDATE ss_character SET location='$location' WHERE id='".$_SESSION['id']."'");
}
This function is then called on the onClick function of the link, as seen below:
echo "<a href=\"play.php?p=location_0\" onclick='updatePlayerLocation(0)'>" . $possibleLocations[0] . "</a><br />";
The $possibleLocations array contains all of the locations that the user can be in, ranging from 0 to 10.
The link seems to work as it loads the page, it just does not execute the MySQL query. My previous research has suggested using AJAX, but as the page needs to refresh, I am wondering if there is an alternative.
Thank you for your time and suggestions! :)