<?php
$groupLimit = '5';
$queryGroupAmount = mysql_query("SELECT owner FROM factions WHERE id = '".$_SESSION['user']['id']."'");
$groupAmount = mysql_num_rows($queryGroupAmount);
$neededCredits = '500';
$queryCreditAmount = mysql_query("SELECT credits FROM users WHERE id = '".$_SESSION['user']['id']."'");
$creditAmount = mysql_result($queryCreditAmount, 0);
if ($groupAmount >= $groupLimit)
{
if ($creditAmount >= $neededCredits)
{
if (isset($_POST['create']))
{
$newCreditAmount = $creditAmount - 500;
mysql_query("INSERT INTO factions(name,owner,official) VALUES('".filter($_POST['name'])."', '".$_SESSION['user']['id']."', '0')");
mysql_query("UPDATE users SET credits= '".$newCreditAmount."' WHERE id = '".$_SESSION['user']['id']."' ");
echo 'Faction has been created!';
}
}
else
{
$leftCredits = $neededCredits - $creditAmount;
echo 'You don\'t have enough credits! You atleast need '.$neededCredits.' to create a group. You currently have '.$creditAmount.' credits, that means you still need '.$leftCredits.' credits to create a group.';
}
}
else
{
echo 'You already have more then '.$groupLimit.' groups! This means you can not make any more.';
}
?>