Hello, some friends and I are modding for a game, the game sends data to a url which triggers a php script.
My php coder is having a problem with accounts duplicating when a player joins, instead of finding the account and updating it.
As you can see pretty simple code. On the game side when a player leaves it sends $uid "the players permant game ID, and $gold "the amount of gold the player is carrying to the database to be stored.
How do we get the code to make sure the $uid already exists and updates it instead of it creating a whole new row in the database?
[code]<?php
include(‘connect.php’);
if (!$connect)
{
die('Could not connect: ’ . mysql_error());
}
$rows = mysql_query(“SELECT * FROM player_data”, $connect);
$num_row = mysql_num_rows($rows);
$id_row = $num_row + 1;
$order=“INSERT INTO player_data (id,game_id,gold) VALUES (’$id_row’,’$_GET[uid]’,’$_GET[gold]’)”;
if (!mysql_query($order,$connect))
{
die('Error: ’ . mysql_error());
}
mysql_close($connect);
?>[/code]