+ Reply to Thread
Results 1 to 10 of 10

Thread: PHP problem

  1. #1
    fierce's Avatar
    fierce is offline x10 Sophmore fierce is an unknown quantity at this point
    Join Date
    Jul 2008
    Location
    Macedonia
    Posts
    222

    PHP problem

    I got error in my game ..ppl can't attack each other ..the reason are the errors in the military.php .. I'm not very good with it so I'd like you to look @ it ..
    <?
    //register globals
    $do_attack = $_POST['do_attack'];
    $target = $_POST['target'];
    $attacktype = $_POST['attacttype'];
    $sendall = $_POST['sendall'];
    $spell_num = $_POST['spell_num'];
    $usent = $_POST['usent'];
    $do_spell = $_POST['do_spell'];

    include("header.php");
    include("magicfun.php");
    $atknames[Standard] = "Standard Attack";
    $atknames[Surprise] = "Surprise Attack";
    $atknames[infantry] = "Infantry Strike";
    $atknames[cavalry] = "Cavalry Assault";
    $atknames[siege] = "Siege Onslaught";
    $atknames[naval] = "Hydro Assault";

    // era of troops, quantity of troops, type of troops, offense or defense
    function CalcPoints($era, $quantity, $ttype, $atype)
    {
    $type = $atype."_".$ttype;
    return $quantity * $era[$type];
    }

    function ClanCheck() // Need to set warflag and netmult
    {
    global $warflag, $netmult, $users, $uclan, $enemy;
    if ($users[clan] == $enemy[clan])
    TheEnd("Cannot attack empires in your clan!");
    if (($uclan[ally1] == $enemy[clan]) || ($uclan[ally2] == $enemy[clan]) || ($uclan[ally3] == $enemy[clan]))
    TheEnd("Your Generals quietly ignore your orders to attack an Ally.");
    if (($uclan[war1] == $enemy[clan]) || ($uclan[war2] == $enemy[clan]) || ($uclan[war3] == $enemy[clan]))
    {
    $warflag = 1.2;
    $netmult = 50;
    }
    }

    function ReadInput ($type)
    {
    global $users, $usent, $enemy, $esent, $sendall, $trplst;

    for ($i = 0; $i < 4; $i++)
    {
    $trp = $trplst[$i];
    $esent[$trp] = $enemy[$trp];
    if ($enemy[forces] > 0) // if enemy shares forces, he can't use them for defense
    $esent[$trp] *= 0.9;
    if ($sendall) // send everything?
    $usent[$trp] = $users[$trp];
    }

    if (($type != 'Standard') && ($type != 'Surprise'))
    {
    for ($i = 0; $i < 4; $i++)
    {
    $trp = $trplst[$i];
    if ($type != $trp)
    {
    $usent[$trp] = 0;
    $esent[$trp] = 0;
    }
    }
    }
    for ($i = 0; $i < 4; $i++)
    CheckQuantity($trplst[$i]);
    }

    function CheckQuantity($type)
    {
    global $users, $uera, $usent;
    fixInputNum($usent[$type]);
    $esent[$type] = round($esent[$type]);
    if ($usent[$type] < 0)
    TheEnd("Cannot attack with a negative number of units!");
    if ($usent[$type] > $users[$type])
    TheEnd("You do not have that many $uera[$type]!");
    }

    function Attack($type)
    {
    global $users, $uera, $usent, $enemy, $eera, $esent, $playerdb, $datetime, $time, $trplst, $warflag;
    $uoffense = 0;
    $edefense = 0;
    for ($i = 0; $i < 4; $i++)
    {
    $uoffense += CalcPoints($uera,$usent[$trplst[$i]],$trplst[$i],o);
    $edefense += CalcPoints($eera,$esent[$trplst[$i]],$trplst[$i],d);
    }
    if ($uoffense == 0)
    TheEnd("Must attack with something!".$trplst[1]."".$uoffense."".$edefense);

    $uoffense *= $users[health] / 100;
    $edefense *= $enemy[health] / 100;

    if ($warflag)
    $uoffense *= 1.2;

    if ($users[era] != $enemy[era]) // only step through time gate if necessary
    {
    if ($users[gate] > $time) // your time gate?
    print "Stepping through your open time gate,<br>
    ";
    elseif ($enemy[gate] > $time) // or enemy's time gate?
    print "Stepping through your enemy's open time gate,<br>
    ";
    }

    if ($type == "Surprise") // surprise attack?
    {
    $offpts *= 1.25;
    $helping = 0;
    $users[health] -= 5;
    }
    elseif (($enemy[clan]) && ($enemy[forces] == 1)) // enemy has allies and sharing forces?
    {
    $dbally = mysql_query("SELECT infantry,cavalry,siege,naval,num,era,race,clan,gat e FROM $playerdb WHERE clan=$enemy[clan] AND forces>0 AND num!=$enemy[num] AND land>0;");
    $helping = mysql_num_rows($dbally);
    }
    if ($helping) // add up allies
    {
    print "$helping empires rushing to defend your target,<br>
    ";
    $emaxdefense = $edefense * 2;
    while ($ally = mysql_fetch_array($dbally))
    {
    $ad = 0;
    if (($enemy[gate] > $time) || ($ally[gate] > $time) || ($enemy[era] == $ally[era]))
    { // defense is limited to eras as well
    addNews(300,$users,$ally,$enemy[num]);
    $arace = loadRace($ally[race]); // adjust according to ally race
    $aera = loadEra($ally[era]); // and era

    for($i = 0; $i < 4; $i++)
    $ad += allyHelp($trplst[$i],$helping) * ($ally[health] / 100);

    $ad = round($ad * $arace[defense]);
    $edefense += $ad;
    }
    }
    if ($edefense > $emaxdefense) // limit ally defense
    $edefense = $emaxdefense;
    }
    $tdefense = $enemy[towers] * 500 * min(1,$enemy[infantry] / (100*$users[towers]+1)); // and add in towers
    $edefense += $tdefense;
    if ($warflag == 0) // war == infinite attacks
    $enemy[attacks]++;
    dobattle($uoffense,$edefense,$type,$tdefense);
    }

    function AllyHelp ($type, $numallies)
    {
    global $enemy, $esent, $ally, $aera;
    $amt = round($ally[$type] * .1);
    if ($amt > $esent[$type] / $numallies)
    $amt = $esent[$type] / $numallies;
    return CalcPoints($aera,$amt,$type,d);
    }

    /*
    dobattle(Offense_Points, Defense_Points, Attack_Type)
    This function:
    determines who won
    calls detloss() to determine troop losses
    calls dealland() if attack was successful
    */
    function dobattle ($op, $dp, $type, $towp)
    {
    $emod = sqrt($op/($dp+1)); // modification to enemy losses
    $umod = sqrt(($dp-$towp)/($op+1)); // modification to attacker losses (towers not included)
    switch ($type)
    {
    case infantry:
    detloss(.1155, .0705, $umod, $emod, infantry);
    break;

    case cavalry:
    detloss(.0985, .0530, $umod, $emod, cavalry);
    break;

    case siege:
    detloss(.0688, .0445, $umod, $emod, siege);
    break;

    case naval:
    detloss(.0450, .0355, $umod, $emod, naval);
    break;

    case Surprise:
    $umod *= 1.2; // fall through

    case Standard:
    detloss(.1455, .0805, $umod, $emod, infantry);
    detloss(.1285, .0730, $umod, $emod, cavalry);
    detloss(.0788, .0675, $umod, $emod, siege);
    detloss(.0650, .0555, $umod, $emod, naval);
    break;
    }
    if($op > $dp * 1.05)
    {
    dealland($type);
    }
    printedreport();
    }

    /*
    This function determines the loss of specific types of troops
    It handles the attacker and defender in one run through
    */
    function detloss($uper, $eper, $umod, $emod, $type)
    {
    global $uloss, $eloss, $usent, $esent;
    if ($usent[$type] > 0) // can't lose more than you send... send none, lose none
    $uloss[$type] = min(mt_rand(0,(ceil($usent[$type] * $uper * $umod)+1)), $usent[$type]);
    else $uloss[$type] = 0;

    $maxkill = round(.9*$usent[$type]) + mt_rand(0, round(.2*$usent[$type] + 1)); // max kills determination (90% - 110%)

    if ($esent[$type] > 0) // he can't lose more than he defended with, or attacker can kill
    $eloss[$type] = min(mt_rand(0,ceil($esent[$type] * $eper * $emod)), $esent[$type], $maxkill);
    else $eloss[$type] = 0; // no troops, no losses}

    I will post the other part of the php in the 2nd post coz it's rly big ..
    4 every found error I will give 50 credits .

    Thx in advance,

    fierce .
    If my post has helped ya or ya like my jokes hit the +REP button ;)
    http://www.eraoferadication.co.cc

    HTML Code:
    http://forums.x10hosting.com/marketplace/85707-req-1000-credits-4-exchange.html

  2. #2
    fierce's Avatar
    fierce is offline x10 Sophmore fierce is an unknown quantity at this point
    Join Date
    Jul 2008
    Location
    Macedonia
    Posts
    222

    Re: PHP problem

    the 2nd part ..

    function LossCalc(&$player, &$ploss)
    {
    global $trplst;
    for ($i = 0; $i < 4; $i++)
    $player[$trplst[$i]] -= $ploss[$trplst[$i]];
    }

    function DealLand($type)
    {
    global $landloss, $buildgain, $enemy, $users;

    // destroy structures
    destroyBuildings('homes',7,70,$type);
    destroyBuildings('GoldMines',7,70,$type);
    destroyBuildings('MilitaryAcademies',7,50,$type);
    destroyBuildings('Barracks',7,70,$type);
    destroyBuildings('MageTowers',7,60,$type);
    destroyBuildings('Farms',7,30,$type);
    destroyBuildings('Towers',7,60,$type);
    destroyBuildings('freeland',10,0,$type); // 3rd argument MUST be 0 - calculate gained freeland below
    $users[freeland] += $landloss - $buildgain;

    // update total land counts
    $users[land] += $landloss;
    $enemy[land] -= $landloss;
    }

    // To handle destroying buildings during successful attacks
    function destroyBuildings ($type, $pcloss, $pcgain, $atktype)
    {
    global $landloss, $buildgain, $enemy, $users;
    $pcloss /= 100;
    $pcgain /= 100;

    if (($atktype == 'cavalry') || ($atktype == 'siege') || ($atktype == 'naval'))
    { // these attacks destroy extra buildings, but fewer are gained
    if ($atktype == 'siege')
    {
    $pcloss *= 1.25;
    $pcgain *= 0.72;
    }
    elseif (($type == 'towers') || ($type == 'mage_towers'))
    {
    $pcloss *= 1.3;
    $pcgain *= 9/13;
    }
    else $pcgain *= 0.9;
    }

    if ($enemy[$type] > 0)
    $loss = mt_rand(1,ceil($enemy[$type] * $pcloss + 2));
    if ($loss > $enemy[$type])
    $loss = $enemy[$type];
    $gain = ceil($loss * $pcgain);

    $enemy[$type] -= $loss;
    $landloss += $loss;
    if ($atktype == Standard) // only gain buildings with standard attack
    {
    $users[$type] += $gain;
    $buildgain += $gain;
    }
    }

    function printedreport()
    {
    global $users, $uloss, $uera, $enemy, $eloss, $eera, $landloss, $buildgain, $trplst;
    if ($landloss)
    print "Your army breaks through $enemy[empire]'s defenses and captures $landloss acres of land! In the effort, you lost:<br>\n";
    else print "After a failing struggle, your army is repelled by $enemy[empire]'s defenses. In the attempt, you lost:<br>\n";
    for ($i = 0; $i < 4; $i++)
    {
    $trp = $trplst[$i];
    if ($uloss[$trp]) print commas($uloss[$trp])." $uera[$trp]<br>\n";
    }
    print "In their defense, $enemy[empire] lost:<br>\n";
    for ($i = 0; $i < 4; $i++)
    {
    $trp = $trplst[$i];
    if ($eloss[$trp]) print commas($eloss[$trp])." $eera[$trp]<br>\n";
    }
    if ($buildgain)
    print "You also captured $buildgain structures!<br>\n";
    if ($enemy[land] == 0)
    {
    ?><span class="cgood"><b><?=$enemy[empire]?> (#<?=$enemy[num]?>)</b> has been destroyed!</span><br>
    <? $users[kills]++;
    }
    }

    // To print the attack table
    function printRow ($type)
    {
    global $users, $uera;
    ?>
    <tr><td><?=$uera[$type]?></td>
    <td class="aright"><?=commas($users[$type])?></td>
    <td class="aright"><input type="text" name="usent[<?=$type?>]" size="8" value="0"></td></tr>
    <?
    }

    // *************
    // End Functions
    // *************

    if ($users[turnsused] <= $config[protection]) // are they under protection?
    TheEnd("Cannot use offensive actions while under protection!");
    if ($users[disabled] == 2) // are they admin?
    TheEnd("Administrative accounts cannot use offensive actions!");

    if ($do_attack)
    {
    if ($users[turns] < 2) // enough turns?
    TheEnd("Not enough turns!");
    if (!$target) // specified target?
    TheEnd("You must specify a target!");
    if ($target == $users[num]) // attacking self?
    TheEnd("Cannot attack yourself!");
    if ($users[health] <= 10)
    TheEnd("You do not have enough health to attack.");
    $enemy = loadUser($target);
    $erace = loadRace($enemy[race]);
    $eera = loadEra($enemy[era]); // load enemy info

    if ($enemy[land] == 0)
    TheEnd("That empire has already been destroyed!");
    if (($enemy[era] != $users[era]) && ($users[gate] <= $time) && ($enemy[gate] <= $time))
    TheEnd("Need to open a Time Gate first!");
    if ($enemy[disabled] >= 2)
    TheEnd("Cannot attack disabled empires!");
    if ($enemy[turnsused] <= $config[protection])
    TheEnd("Cannot attack empires under new player protection!");
    if ($enemy[vacation] > $config[vacationdelay])

    TheEnd("Cannot attack empires on vacation!");
    $warflag = 0;
    $netmult = 20;

    $uclan = loadClan($users[clan]);

    if ($enemy[clan])
    ClanCheck();

    if ($enemy[networth] > $users[networth] * $netmult)
    TheEnd("Your Generals flatly refuse to attack such a strong opponent!");
    if ($users[networth] > $enemy[networth] * $netmult)
    TheEnd("Your Generals politely refuse your orders to attack a defenseless empire!");

    if ($warflag == 0)
    {
    if ($enemy[attacks] > 20)
    TheEnd("Too many recent attacks on that empire. Try again in one hour.");
    $revolt = 1;
    if ($users[networth] > $enemy[networth] * 2.5)
    { // Shame is less powerful than fear
    ?><span class="cwarn">Your military is ashamed by your attack on such a weak opponent. Many desert!</span><br>
    <? $revolt = 1 - $users[networth] / $enemy[networth] / 125;
    }
    elseif ($enemy[networth] > $users[networth] * 2.5)
    {
    ?><span class="cwarn">Your military trembles at your attack on such a strong opponent. Many desert!</span><br>
    <? $revolt = 1 - $enemy[networth] / $users[networth] / 100;
    }
    if ($revolt < .9)
    $revolt = .9;
    for ($i = 0; $i < 4; $i++)
    $users[$trplst[$i]] = round($users[$trplst[$i]] * $revolt);
    }

    readInput($attacktype);

    Attack($attacktype);

    // record losses

    losscalc($users, $uloss);
    losscalc($enemy, $eloss);

    if (!$landloss)
    $landloss = 0;
    switch ($attacktype)
    {
    case 'Standard':addNews(302,$users,$enemy,$landloss,$el oss[infantry],$eloss[cavalry],$eloss[siege],$eloss[naval],$uloss[infantry],$uloss[cavalry],$uloss[siege],$uloss[naval]); break;
    case 'Surprise':addNews(303,$users,$enemy,$landloss,$el oss[infantry],$eloss[cavalry],$eloss[siege],$eloss[naval],$uloss[infantry],$uloss[cavalry],$uloss[siege],$uloss[naval]); break;
    case 'infantry': addNews(304,$users,$enemy,$landloss,$eloss[infantry],$uloss[infantry]); break;
    case 'cavalry': addNews(305,$users,$enemy,$landloss,$eloss[cavalry],$uloss[cavalry]); break;
    case 'siege': addNews(306,$users,$enemy,$landloss,$eloss[siege],$uloss[siege]); break;
    case 'naval': addNews(307,$users,$enemy,$landloss,$eloss[naval],$uloss[naval]); break;
    }
    if ($enemy[land] == 0)
    addNews(301,$users,$enemy,0);

    $users[attacks] -= 2;
    if ($users[attacks] < 0)
    $users[attacks] = 0;
    $users[offtotal]++;
    if ($landloss)
    $users[offsucc]++;
    else $enemy[defsucc]++;
    $enemy[deftotal]++;
    $users[health] -= 8;
    saveUserDataNet($users,"networth infantry cavalry siege naval land homes mines academies barracks mage_towers farms towers freeland offsucc offtotal attacks health kills");
    saveUserDataNet($enemy,"networth infantry cavalry siege naval land homes mines academies barracks mage_towers farms towers freeland defsucc deftotal attacks");

    taketurns(2,attack);
    }
    ?>
    <form method="post" action="<?=$config[main]?>?action=military">
    <table class="inputtable">
    <tr><td colspan="3" class="acenter">Empire number to attack? <input type="text" name="target" size="5" value="<?php echo $_GET['prof_target']; ?>"></td></tr>
    <tr><td colspan="3" class="acenter">Attack Type: <select name="attacktype" size="1">
    <option value="Standard"><?=$atknames[Standard]?></option>
    <option value="Surprise"><?=$atknames[Surprise]?> (no allies)</option>
    <option value="infantry"><?=$atknames[infantry]?></option>
    <option value="cavalry"><?=$atknames[cavalry]?></option>
    <option value="siege"><?=$atknames[siege]?></option>
    <option value="naval"><?=$atknames[naval]?></option>
    </select></td></tr>
    <tr><th class="aleft">Unit</th>
    <th class="aright">Owned</th>
    <th class="aright">Send</th></tr>
    <?
    for($i = 0; $i < 4; $i++)
    printRow($trplst[$i]);
    ?>
    <tr><td colspan="3" class="acenter"><input type="checkbox" name="sendall" value="1">Send Everything</td></tr>
    <tr><td colspan="3" class="acenter"><input type="submit" name="do_attack" value="Send Attack"></td></tr>
    </table>
    </form>
    <hr>
    <form method="post" action="<?=$config[main]?>?action=military">
    <table class="inputtable">
    <tr><td class="acenter">Empire to cast spell on? <input type="text" name="target" size="5"></td></tr>
    <tr><td><select name="spell_num" size="1">
    <option value="0">Select a Spell</option>
    <?
    for ($i = 1; $i <= 12; $i++)
    if ($sptype[$i] == 'o')
    printMRow($i);
    ?>
    </select></td></tr>
    <tr><td class="acenter"><input type="submit" name="do_spell" value="Cast Spell"></td></tr>
    </table>
    </form>
    <?
    if ($users[shield] > $time)
    print "<i>We currently have a shield against magic which will last for ".round(($users[shield]-$time)/3600,1)." more hours.</i><br>\n";
    print "<i>The health of our forces and people is at $users[health]%!</i><br>\n";
    if ($users[gate] > $time)
    print "<i>We currently have an open time portal which will last for ".round(($users[gate]-$time)/3600,1)." more hours.</i><br>\n";
    TheEnd("");
    ?>

    you can check the game as well www.eraoferadication.co.cc

    fierce .
    If my post has helped ya or ya like my jokes hit the +REP button ;)
    http://www.eraoferadication.co.cc

    HTML Code:
    http://forums.x10hosting.com/marketplace/85707-req-1000-credits-4-exchange.html

  3. #3
    Scoochi2's Avatar
    Scoochi2 is offline x10 Sophmore Scoochi2 is an unknown quantity at this point
    Join Date
    Aug 2008
    Location
    Southport!
    Posts
    185

    Re: PHP problem

    wow... learn to use the [code] bbcode ;)
    Also, it would've been a better idea to upload the file as an attachment if it's so big that it needs 2 large posts! lol.

    But anyway, in your second post, check the last switch. Your variables have spaces in them for the first two cases.
    switch ($attacktype)
    {
    case 'Standard':addNews(302,$users,$enemy,$landloss,$el oss[infantry],$eloss[cavalry],$eloss[siege],$eloss[naval],$uloss[infantry],$uloss[cavalry],$uloss[siege],$uloss[naval]); break;
    case 'Surprise':addNews(303,$users,$enemy,$landloss,$el oss[infantry],$eloss[cavalry],$eloss[siege],$eloss[naval],$uloss[infantry],$uloss[cavalry],$uloss[siege],$uloss[naval]); break;

    case 'infantry': addNews(304,$users,$enemy,$landloss,$eloss[infantry],$uloss[infantry]); break;
    case 'cavalry': addNews(305,$users,$enemy,$landloss,$eloss[cavalry],$uloss[cavalry]); break;
    case 'siege': addNews(306,$users,$enemy,$landloss,$eloss[siege],$uloss[siege]); break;
    case 'naval': addNews(307,$users,$enemy,$landloss,$eloss[naval],$uloss[naval]); break;
    }
    Remove those spaces.
    Code:
    case 'Standard':addNews(302,$users,$enemy,$landloss,$eloss[infantry],$eloss[cavalry],$eloss[siege],$eloss[naval],$uloss[infantry],$uloss[cavalry],$uloss[siege],$uloss[naval]); break;
    case 'Surprise':addNews(303,$users,$enemy,$landloss,$eloss[infantry],$eloss[cavalry],$eloss[siege],$eloss[naval],$uloss[infantry],$uloss[cavalry],$uloss[siege],$uloss[naval]); break;
    Syntax wise, I think that's your only error. There's too much code for me to look through through.

    If it still doesn't work, try echoing variables at various points to make sure they're all what they should be. If you find one of your variables suddenly changing between two points, there's a hell of a lot less code to search through to find it ;)
    Last edited by Scoochi2; 10-12-2008 at 04:57 PM.
    If anyone can see it, my post was meant for anyone who reads it. Don't take it personally or think I'm being condescending... :nuts:

  4. #4
    natsuki's Avatar
    natsuki is offline x10 Sophmore natsuki is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    112

    Re: PHP problem

    I was about to say the same: you should have uploaded the files instead because it's too long to be posted.

    This is what happens when you mess around something you don't even know... And this script is interesting but it definitely is a lot of code. Know any particular errors generated and in what lines?

    It will take a while to browse through all this

    EDIT:
    Are these unquoted array keys constants defined somewhere else?
    Code:
    $atknames[Standard] = "Standard Attack";
    $atknames[Surprise] = "Surprise Attack";
    $atknames[infantry] = "Infantry Strike";
    $atknames[cavalry] = "Cavalry Assault";
    $atknames[siege] = "Siege Onslaught";
    $atknames[naval] = "Hydro Assault";
    ?>
    That's the only thing I noticed so far.
    Is this just a typo or is it really correct?
    Code:
    <?
    //register globals
    $do_attack = $_POST['do_attack'];
    $target = $_POST['target'];
    $attacktype = $_POST['attacttype'];
    $sendall = $_POST['sendall'];
    $spell_num = $_POST['spell_num'];
    $usent = $_POST['usent'];
    $do_spell = $_POST['do_spell'];
    I think you can't parse an array (assuming the key is a defined constant string) but if it's an unquoted string then it's ok. And you have a space in gat e, it was supposed to be gate?
    Code:
    	if ($type == "Surprise") // surprise attack?
    	{
    		$offpts *= 1.25;
    		$helping = 0;
    		$users[health] -= 5;
    	}
    	elseif (($enemy[clan]) && ($enemy[forces] == 1)) // enemy has allies and sharing forces?
    	{
    		$dbally = mysql_query("SELECT infantry,cavalry,siege,naval,num,era,race,clan,gat e FROM $playerdb WHERE clan=$enemy[clan] AND forces>0 AND num!=$enemy[num] AND land>0;");
    		$helping = mysql_num_rows($dbally);
    	}
    	if ($helping) // add up allies
    This function is missing the closing curly brace. And functions inside a function...?
    Code:
    /*
    This function determines the loss of specific types of troops
    It handles the attacker and defender in one run through
    */
    function detloss($uper, $eper, $umod, $emod, $type)
    {
    	global $uloss, $eloss, $usent, $esent;
    	if ($usent[$type] > 0) // can't lose more than you send... send none, lose none
    	$uloss[$type] = min(mt_rand(0,(ceil($usent[$type] * $uper * $umod)+1)), $usent[$type]);
    	else $uloss[$type] = 0;
    
    	$maxkill = round(.9*$usent[$type]) + mt_rand(0, round(.2*$usent[$type] + 1)); // max kills determination (90% - 110%)
    
    	if ($esent[$type] > 0) // he can't lose more than he defended with, or attacker can kill
    	$eloss[$type] = min(mt_rand(0,ceil($esent[$type] * $eper * $emod)), $esent[$type], $maxkill);
    	else $eloss[$type] = 0; // no troops, no losses}
    
    	function LossCalc(&$player, &$ploss)
    	{
    		global $trplst;
    		for ($i = 0; $i < 4; $i++)
    		$player[$trplst[$i]] -= $ploss[$trplst[$i]];
    	}...
    I really don't know about a lot of those unquoted array keys, if they are defined constants (because they were not written the usual UPPER_CASE) but they look readable except there was no comment about them.
    I suggest you use XML and place all your configs there, probably when your game starts to get so big and complicated. (not really required)
    And you're using short php tags <? instead of the usual <?php but that won't be a problem if your php hosting allows that anyway.
    Last edited by natsuki; 10-12-2008 at 06:12 PM.

  5. #5
    sunils's Avatar
    sunils is offline x10 Spammer sunils is an unknown quantity at this point
    Join Date
    Jan 2008
    Location
    Chennai ,India
    Posts
    2,264

    Re: PHP problem

    If you have posted the error along with the post, then it would have been easier to find a solution.
    [LEFT][B]Sunil Sankar
    -------------------------------------------------------------------------

  6. #6
    fierce's Avatar
    fierce is offline x10 Sophmore fierce is an unknown quantity at this point
    Join Date
    Jul 2008
    Location
    Macedonia
    Posts
    222

    Re: PHP problem

    this is what you'll get if you try to attack some1 " Must attack with something!cavalry00 " ...
    Edit:
    few more errors ...

    Warning: mysql_query() [function.mysql-query]: Access denied for user 'fierce'@'localhost' (using password: NO) in /home/fierce/public_html/html.php on line 3

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/fierce/public_html/html.php on line 3

    Warning: mysql_query() [function.mysql-query]: Access denied for user 'fierce'@'localhost' (using password: NO) in /home/fierce/public_html/funcs.php on line 41

    Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/fierce/public_html/funcs.php on line 41

    Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in /home/fierce/public_html/funcs.php on line 41

    Warning: Cannot modify header information - headers already sent by (output started at /home/fierce/public_html/html.php:3) in /home/fierce/public_html/html.php on line 65

    Warning: Cannot modify header information - headers already sent by (output started at /home/fierce/public_html/html.php:3) in /home/fierce/public_html/html.php on line 66

    NOTICE : I made .txt file you can get the whole code here
    www.eraoferadication.co.cc/problem.txt

    4 every error you find I will give 50 credits .. if ya fix it completely I will give 500 credits .

    Thx in Advance,

    fierce .
    Edit:
    Thx alot natsuki your post helped me make it work .. I will send credits ..and to you scoochi as well 4 the try .

    fierce .
    Last edited by fierce; 10-13-2008 at 08:49 AM. Reason: Automerged Doublepost
    If my post has helped ya or ya like my jokes hit the +REP button ;)
    http://www.eraoferadication.co.cc

    HTML Code:
    http://forums.x10hosting.com/marketplace/85707-req-1000-credits-4-exchange.html

  7. #7
    Myokram is offline x10Hosting Member Myokram is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    30

    Re: PHP problem

    Can you put the part of your code in which you make the connection to MySQL server? Why aren't you putting a password?

    Warning: mysql_query() [function.mysql-query]: Access denied for user 'fierce'@'localhost' (using password: NO) in /home/fierce/public_html/html.php on line 3
    Greets!

  8. #8
    natsuki's Avatar
    natsuki is offline x10 Sophmore natsuki is an unknown quantity at this point
    Join Date
    Sep 2008
    Posts
    112

    Re: PHP problem

    I think that is not the file with the problems. it's html.php and the mysql errors spawn from the first error which is what Myokram said. When you fix it, you shouldn't be getting the rest of the errors.

    headers were already sent meaning you have something already written in the page, either by echo or some whitespace or html, you can't modify the headers anymore, even
    PHP Code:
    <?php ?>
    <?php ?>
    might have a whitespace

    we need the code contained in html.php to solve that one

    thanks for the credits and no prob! i actually don't know how to use these credits or even what they are ^^;
    Last edited by natsuki; 10-14-2008 at 01:56 PM.

  9. #9
    Salvatos's Avatar
    Salvatos is offline x10 Lieutenant Salvatos is an unknown quantity at this point
    Join Date
    Jun 2006
    Location
    Québec, Canada
    Posts
    271

    Re: PHP problem

    Quote Originally Posted by natsuki View Post
    i actually don't know how to use these credits or even what they are ^^;
    x10 used to have a kind of cash shop where you could buy stuff like domain names and instant-unsuspension. However, as far as I know, it's been under maintenance for quite a few months because of a compatibility issue with the new version of the forums.

  10. #10
    Myokram is offline x10Hosting Member Myokram is an unknown quantity at this point
    Join Date
    Oct 2008
    Posts
    30

    Re: PHP problem

    Quote Originally Posted by natsuki View Post
    headers were already sent meaning you have something already written in the page, either by echo or some whitespace or html, you can't modify the headers anymore, even
    PHP Code:
    <?php ?>
    <?php ?>
    might have a whitespace

    we need the code contained in html.php to solve that one
    In fact it looks more like, as you frist said, MySQL connection problem is causing the rest of errors, including those about the sent headers. One error message displayed means sending header to the client. All errors come from the first one.

    :happysad:

+ Reply to Thread

Similar Threads

  1. Replies: 3
    Last Post: 03-10-2008, 12:22 PM
  2. problem in php mail function and smtp
    By idrees in forum Free Hosting
    Replies: 2
    Last Post: 02-08-2008, 05:16 PM
  3. Sigo con problemas con phpbb2
    By reciecho in forum Soporte
    Replies: 7
    Last Post: 10-20-2007, 06:28 PM
  4. "PHP Startup: Invalid Library" - Interesting error
    By javaguy78 in forum Free Hosting
    Replies: 5
    Last Post: 03-27-2007, 02:33 PM
  5. php ad code problem
    By sourabhj in forum Free Hosting
    Replies: 7
    Last Post: 08-22-2006, 08:28 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers