All pastes #196036 Raw Edit

Someone

public text v1 · immutable
·published 2006-10-10 07:51 UTC
rendered paste body
function update_stats($user_id, $stats_array)
{
	global $db;

	if (!is_array($stats_array))
	{
		message_die(GAME_ERROR, 'ERROR: $stats_array must be an array.');
	}

	$sql_array = array();
	foreach ($stats_array as $stat => $value)
	{
		if (is_int($value) || is_bool($value))
		{
			$value = intval($value);
		}
		else if (is_float($value))
		{
			$value = floatval($value);
		}
		else if (is_string($value))
		{
			$value = str_replace('\"', '""', $value);
		}

		$sql_array[] = '`' . $stat . '` = ' . $stat . ' ' . $value;
	}

	$sql = "UPDATE bet_users_stats SET " . implode(', ', $sql_array) . " WHERE user_id = " . intval($user_id);
	if ( !($db->sql_query($sql)) ) { message_die(GAME_ERROR, 'ERROR: Unable to update statistics.'); }
}