Jump to content

Recommended Posts

Hi all this code calls is m armory but for some stupid reason it is not calling the weapons from the SQL DB

 

here is Armory.php

<?php
// Tabsize = 2

//start title
$pagetitle="Armory";
//end title
if (isSet($_GET["strErr"])) { $msg = $_GET["strErr"]; }
require("db_connect.php");
require("functions/armory2.php");
require("functions/global.php");

if( isset($_SESSION['userid']) ){
$user=getUserInfo($_SESSION['userid']);
$deflist=getDefenseList($user['raceID']);
$atklist=getAttackList($user['raceID']);
} else {
message("You are not logged in!","index.php");
}
$msbutton=getMothershipButton($_SESSION['userid']);

if($_POST['buyms']){
$mscost=250000000;
if(($user['Naquadah']-$mscost)>=0){
	createms($_SESSION['userid'], $mscost);
}else{
header("Location: armory.php?StrErr=not enough Naquadah");
}
}
if($_POST['enterms']){
header("Location: mothership.php");
}


include("includes/header.php");



function getWeapons($userID, $raceID, $attack) {
$user_weapons = mysql_query("select * from `user_weapons` where `userid`='$userID' AND `quantity` > 0 order by strength asc") or die(mysql_error());
	while($row=mysql_fetch_array($user_weapons)){
		$q="SELECT * FROM `race_weapons` WHERE `weaponID` = '".$row['weaponID']."' AND `weaponAttack` = '$attack'";
		$v=mysql_query($q);
		$rowcount=mysql_num_rows($v);
		$wep=mysql_fetch_array($v);
		if ($row["strength"] < $wep['weaponDefaultStrength']) {
			$strengthDiff = number_format(($wep['weaponDefaultStrength'] - $row["strength"])*(6*$row["quantity"])); 
			} else {
				$strengthDiff = 0;
				}
		if($rowcount<=0){
		$output.="";
		}else{
		$output .= "<tr>
						<td style=\"FONT-SIZE: 8pt;\">".$wep['weaponName']."</td>
						<td align=\"right\" style=\"FONT-SIZE: 8pt;\">
          " . number_format($row['quantity']) . "        </td>
              <td align=\"middle\" style=\"FONT-SIZE: 8pt;\">
         " . number_format($row['strength']) . "          /
          " . number_format($wep['weaponDefaultStrength']) . "        </td>
        <form action=\"armory3.php\" method=\"post\">
          <td width=\"100%\">
            <table cellSpacing=\"0\" cellPadding=\"2\" width=\"100%\" border=\"0\" style=\"FONT-SIZE: 8pt;\">
              <tbody>
              <tr>
                <td style=\"BORDER-BOTTOM: medium none\">
                  <input type=\"input\" maxLength=\"5\" size=\"3\" value=\"0\" name=\"repairQuantity\" style=\"FONT-SIZE: 8pt;\">
								<input type=\"hidden\" name=\"wid\" value=\"" . $row["wid"] . "\">
                </td>
                <td style=\"FONT-SIZE: 8pt; BORDER-BOTTOM: medium none\" width=\"100%\">
							<input type=\"hidden\" name=\"action\" value=\"repair\">
                <input style=\"FONT-SIZE: 8pt; WIDTH: 40%\" type=\"submit\" value=\"" . number_format((6*$row['quantity'])). " /pt\" name=\"dorepair\">
							<input style=\"FONT-SIZE: 8pt; WIDTH: 45%\" type=\"submit\" value=\"$strengthDiff\" name=\"repairAll\">
                </td>
              </tr>
              </tbody>
            </table>
          </td>
        </form>
        <form action=\"armory3.php\" method=\"post\">
          <td align=\"left\" width=\"100%\">
            <table cellSpacing=\"0\" cellPadding=\"1\" width=\"100%\" border=\"0\" style=\"FONT-SIZE: 8pt;\">
              <tbody>
              <tr>
                <td style=\"FONT-SIZE: 8pt;\" align=\"left\">
                  <input type=\"input\" maxLength=\"5\" size=\"3\" value=\"0\" name=\"scrapQuantity\" style=\"FONT-SIZE: 8pt;\">
								<input type=\"hidden\" name=\"wid\" value=\"" . $row["wid"] . "\">
                </td>
                <td width=\"100%\" align=\"left\">
                  <input style=\"FONT-SIZE: 8pt;\" type=\"submit\" value=\"Sell for " . number_format($wep["weaponPrice"]*. . " Naquadah\" name=\"scrapDo\" width=\"100%\">
								<input type=\"hidden\" name=\"action\" value=\"scrap\">
                </td>
              </tr>
              </tbody>
            </table>
          </td>
        	</form>
        	</tr>";
		}
	}
	return $output;
}

?>
<html>
<head>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
<script src="js/xmlhttp.js" type="text/javascript"></script>
<SCRIPT language=javascript src="js/js.js"></SCRIPT>
<LINK href="css/common.css" type=text/css rel=stylesheet>

</style>
</head>
<body>
<center><Table width=100% cellspacing=1 cellpadding=5>
<tr>
<td width=15% valign=top><?php include("includes/navi.php"); ?></td><td valign=top>
<?php if($msg!=""){ ?><b><i><center><font size=+0><?php echo($msg); ?></font></center></i></b> <?php } ?><Br><?php echo($msbutton); ?><br>
    <table width="100%" border="0" cellspacing="1" cellpadding="5">
      <tr>
			<td valign=top colspan="2">
				<table width="100%" border="0" cellspacing="1" cellpadding="5" class="table_lines">
					<tr>
              <th colspan=4><center>Armory</center></th>
            </tr>
					<tr>
						<th class="subh" align="left" style="FONT-SIZE: 10pt;"><font color="white">Assault weapons</font></th>
						<th class="subh" align="right" style="FONT-SIZE: 10pt;"><font color="white">Quantity</font></th>
						<th class="subh" style="FONT-SIZE: 10pt;"><center><font color="white">Strength</font></center></th>
						<th class="subh" style="FONT-SIZE: 10pt;"><center><font color="white">Repair<br>Naquadah per point / ALL</font></center></th>
						<th class="subh" style="FONT-SIZE: 10pt;"><center><font color="white">Scrap / Sell</font></center></th>
					</tr>
					<? print getWeapons($user["userid"],$user["raceID"],"1"); ?>
					<tr>
						<th class="subh" align="left" style="FONT-SIZE: 10pt;"><font color="white">Defense weapons</font></th>
						<th class="subh" align="right" style="FONT-SIZE: 10pt;"><font color="white">Quantity</font></th>
						<th class="subh" style="FONT-SIZE: 10pt;"><center><font color="white">Strength</font></center></th>
						<th class="subh" style="FONT-SIZE: 10pt;"><center><font color="white">Repair<br>Naquadah per point / ALL</font></center></th>
						<th class="subh" style="FONT-SIZE: 10pt;"><center><font color="white">Scrap / Sell</font></center></th>
					</tr>
					<? print getWeapons($user["userid"],$user["raceID"],"0"); ?>
				</table>
			</td>
		</tr>
	<tr>
	<td>
<TABLE width="100%">

	<TR>
	<TD style="PADDING-RIGHT: 25px" vAlign=top width="50%"><table width="100%" cellpadding="0" cellspacing="0" class="table_lines">
          <tr>
            <th colspan="3">Military Effectiveness</th>
          </tr>
          <tr>
            <td><strong>Overall</strong></td>
            <td align="right"><?php echo(number_format(getAtkPow($user['userid'])+getDefPow($user['userid'])+getSpyPow($user['userid']))); ?></td>
            <td align="right">Ranked: <?php echo(number_format($user['overallRank'])); ?></td>
          </tr>
          <tr>
            <td><strong>Strike Action</strong></td>
            <td align="right"><?php echo(number_format(getAtkPow($user['userid']))); ?></td>
            <td align="right">Ranked: <?php echo(number_format($user['attackRank'])); ?></td>
          </tr>
          <tr>
            <td><strong>Defensive Action</strong></td>
            <td align="right"><?php echo(number_format(getDefPow($user['userid']))); ?></td>
            <td align="right">Ranked: <?php echo(number_format($user['defenseRank'])); ?></td>
          </tr>
          <tr>
            <td><strong>Covert Action</strong></td>
            <td align="right"><?php echo(number_format(getSpyPow($user['userid']))); ?></td>
            <td align="right" valign="top">Ranked: <?php echo(number_format($user['covertRank'])); ?></td>
          </tr>
          <tr>
            <td><strong>Mothership Action</strong></td>
            <td align="right"><font size=-1><?php echo(number_format(getFleetPower($user['userid']))); ?></font></td>
            <td align="right">Ranked: <?php echo(number_format($user['fleetRank'])); ?></td>
          </tr>
        </table>
	  <br>
	  <br>
          <table width="100%" border="0" cellspacing="1" cellpadding="5" class="table_lines" style="FONT-SIZE: 10pt;">
            <tr>
              <th align=center colspan=2>Populace</th>
              
          </tr>
            <tr>
              <td>Assault Trooper </td>
              <td><?php echo(number_format($user['attackTroops'])); ?></td>
            </tr>
            <tr>
              <td>Gaurd</td>
              <td><?php echo(number_format($user['defenseTroops'])); ?></td>
            </tr>
            <tr>
              <td>Civillian</td>
              <td><?php echo(number_format($user['untrainedTroops'])); ?></td>
            </tr>
            <tr>
              <td>Covert Operative </td>
              <td><?php echo(number_format($user['covertTroops'])); ?></td>
            </tr>
          </table>
			</td><td valign=top><Br>
       
	  <form name=buywep id=buywep action='armory3.php' method="POST">
          <table width="100%" border="0" cellspacing="1" cellpadding="5" class="table_lines">
             <tr>
              <th colspan=4>Buy Weaponry</th>
            </tr>
		<tr>
              <th colspan=4><font size=-1>Assault Weapons</font></th>
            </tr>
            <tr>
              <td>Weapon Name </td>
              <td>Strength</td>
              <td>Cost</td>
              <td>Amount</td>
            </tr>
		<?php

		 print($atklist); ?>
            <tr>
              <th colspan=4><font size=-1>Defense Weapons</font></th>
            </tr>
            <tr>
              <td>Weapon Name </td>
              <td>Strength</td>
              <td>Cost</td>
              <td>Amount</td>
            </tr>
		<?php

		 print($deflist); ?>
            <tr>
              <td colspan=4><div align="center">
                <label>
                <input name="purchase" type="submit" id="purchase" value="Purchase Weaponry">
	<input type="hidden" name="action" value="purchase">
                </label>
              </div></td>
            </tr>
          </table></form></td>
		</tr>
		<tr>

      </tr>
    </table> 
</td></tr></Table>
</td></tr></Table><br>
  <?php include("includes/bottom.php"); ?>
  
</center>
</body>
</html>

 

Here is the Armory2.php

 

<?php

//$weaponatklimit=7;
//$weapondeflimit=7;
//to change the limit edit the functions right below race weapons from 7 to the # you want
//
//human weapon
//

//
//begin weapon retrieval
//
$i=1;
function getAttackList($rid){
global $conf;
//we are gonna loop it around town
$q="SELECT * FROM `race_weapons` WHERE `raceID` = '$rid' AND `weaponAttack` = '1'";
$v=mysql_query($q);
while($row=mysql_fetch_array($v)){
$i+=1;
$weaponlist.="
<tr>
<td>".$row['weaponName']."</td>
<td>".number_format($row['weaponDefaultStrength'])."</td>
<td>".number_format($row['weaponPrice'])."</td>
<Td><input type=text value=0 name='atk".$i."' id='atk".$i."' size=4></td>
</tr>
";

}
return $weaponlist;
}
$i=1;
function getDefenseList($rid){
global $conf;
$q="SELECT * FROM `race_weapons` WHERE `raceID` = '$rid' AND `weaponAttack` = '0'";
$v=mysql_query($q);
while($row=mysql_fetch_array($v)){
$i+=1;
$weaponlist.="
<tr>
<td>".$row['weaponName']."</td>
<td>".number_format($row['weaponDefaultStrength'])."</td>
<td>".number_format($row['weaponPrice'])."</td>
<Td><input type=text value=0 name='def".$i."' id='def".$i."' size=4></td>
</tr>
";

}
//$weaponlist.="<Tr><Td>failed</td></tr>";
return $weaponlist;
}

function weaponExists($weaponID, $userID) {
$user_weapons = mysql_query("select quantity from user_weapons where weaponID=\"" . $weaponID . "\" && userid=\"" . $userID . "\"") or DIE(mysql_error());
if (mysql_num_rows($user_weapons)) {
	return mysql_result($user_weapons,0,"quantity");	// Returns quantity if weapon exists in user's database
	} else {
		return FALSE;																		// Otherwise return false
		}
}

function weaponAffordable($weaponID, $weaponAmount, $userID) {
$user_users = mysql_query("select Naquadah from user_users where userid=\"$userID\"") or DIE(mysql_error());
$userNaquadah = mysql_result($user_users,0,"Naquadah");
$race_weapons = mysql_query("select weaponPrice from race_weapons where weaponID=\"$weaponID\"") or DIE(mysql_error());
$weaponPrice = mysql_result($race_weapons,0,"weaponPrice");
if (($weaponPrice*$weaponAmount) <= $userNaquadah) {
	return TRUE;
	} else {
		return FALSE;
		}
}

function purchaseWeapon($weaponID, $weaponExists, $weaponAmount, $userID) {
if (weaponAffordable($weaponID, $weaponAmount, $userID)) {
	$race_weapons = mysql_query("select weaponPrice from race_weapons where weaponID=\"" . $weaponID . "\"") or DIE(mysql_error());
	$weaponPrice = (mysql_result($race_weapons,0,"weaponPrice")*$weaponAmount);
	$users_user = mysql_query("update user_users SET Naquadah=Naquadah-$weaponPrice where userid=\"" . $userID . "\"") or DIE(mysql_error());
	if ($weaponExists) {
		$race_weapons = mysql_query("select weaponDefaultStrength from race_weapons where weaponID=\"" . $weaponID . "\"") or DIE(mysql_error());
		$weaponDefaultStrength = mysql_result($race_weapons,0,"weaponDefaultStrength");
		$user_weapons = mysql_query("select strength from user_weapons where userid=\"" . $userID . "\" && weaponID=\"" . $weaponID . "\"") or DIE(mysql_error());
		$strength = mysql_result($user_weapons,0,"strength");
		// Calculate new weapon strength
		$newstrength = ((($strength*$weaponExists) + ($weaponDefaultStrength*$weaponAmount)) / ($weaponExists + $weaponAmount));
		$purchase_sql = mysql_query("update user_weapons set quantity=\"" . ($weaponExists+$weaponAmount) . "\", strength=\"$newstrength\" where userid=\"" . $userID . "\" && weaponID=\"" .$weaponID. "\"") or DIE(mysql_error());
		return TRUE;
		} else {
			$race_weapons = mysql_query("select weaponDefaultStrength from race_weapons where weaponID=\"" . $weaponID . "\"") or DIE(mysql_error());
			$strength = mysql_result($race_weapons,0,"weaponDefaultStrength");
			$purchase_sql = mysql_query("insert into user_weapons (wid, weaponID, strength, userid, quantity) VALUES (\"\", \"" . $weaponID . "\", \"$strength\", \"" . $userID . "\", \"" . $weaponAmount . "\")") or DIE(mysql_error());
			return TRUE;
			}
	} else {
		return FALSE;
		}
}

function getWeaponData($weapons=array(), $attack, $raceID) {
$race_weapons = mysql_query("select weaponID, weaponName, weaponDefaultStrength, weaponPrice from race_weapons where raceID=\"" . $raceID . "\" && weaponAttack=\"$attack\" order by weaponName asc") or DIE(mysql_error());
$i = 0; $weaponAmount = sizeof($weapons); $weaponData = array();
while ($i < mysql_num_rows($race_weapons)) {
	$weaponCounter = 0;
	while ($weaponCounter < $weaponAmount) {
		if (mysql_result($race_weapons,$i,"weaponID")==$weapons[$weaponCounter]) {
			$weaponData[($weapons[$weaponCounter])]["name"] = mysql_result($race_weapons,$i,"weaponName");
			$weaponData[($weapons[$weaponCounter])]["defaultStrength"] = mysql_result($race_weapons,$i,"weaponDefaultStrength");
			$weaponData[($weapons[$weaponCounter])]["price"] = mysql_result($race_weapons,$i,"weaponPrice");
			}
		$weaponCounter++;
		}
	$i++;
	}
return $weaponData;
}

function getMothershipButton($userid){
$sql="SELECT * FROM `user_mothership` WHERE `userid` = '$userid'";
$query=mysql_query($sql);
$rowcount=mysql_num_rows($query);
if($rowcount<=0){
$button="<center><form name=msbuy id=msbuy action='' method=POST><input type=submit name='buyms' id='buyms' value='Buy Flagship For 250,000,000'></form></center>";
}else{
$ms=mysql_fetch_array($query);
$button="<center><form name=msbuy id=msbuy action='' method=POST><input type=submit name='enterms' id='enterms' value='Enter Control For The ".$ms['shipName']."'></form></center>";
}
return $button;
}

function createms($id,$cost){
$q="INSERT INTO `user_mothership` (`shipid`,`userid`,`shipName`) VALUES ('','$id','Yt-100')";
mysql_query($q);
$q="UPDATE `user_users` SET `Naquadah` = `Naquadah` - '$cost' WHERE `userid` = '$id'";
mysql_query($q);
header("Location: armory.php?strErr=Flagship Constructed");
}

?>

 

Here is the SQL:

 

CREATE TABLE `race_weapons` (
  `weaponID` int(11) NOT NULL auto_increment,
  `raceID` int(11) NOT NULL default '0',
  `weaponName` varchar(100) NOT NULL default '',
  `weaponAttack` tinyint(1) NOT NULL default '0',
  `weaponDefaultStrength` int(11) NOT NULL default '0',
  `weaponPrice` int(11) NOT NULL default '0',
  PRIMARY KEY  (`weaponID`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=29 ;

-- 
-- Dumping data for table `race_weapons`
-- 

INSERT INTO `race_weapons` VALUES (1, 1, 'Antique Pistol', 1, 5, 1000);
INSERT INTO `race_weapons` VALUES (2, 1, 'M1 Grant', 1, 10, 1800);
INSERT INTO `race_weapons` VALUES (3, 1, 'Rifle', 1, 20, 3200);
INSERT INTO `race_weapons` VALUES (4, 1, 'Sniper', 1, 40, 5100);
INSERT INTO `race_weapons` VALUES (5, 1, 'Machine Gun', 1, 160, 16400);
INSERT INTO `race_weapons` VALUES (6, 1, 'Armored Machine Gun', 1, 540, 52400);
INSERT INTO `race_weapons` VALUES (7, 1, 'Light Tank', 1, 2360, 169800);
INSERT INTO `race_weapons` VALUES (8, 1, 'Shotgun', 0, 5, 1000);
INSERT INTO `race_weapons` VALUES (9, 1, 'Magnum', 0, 10, 1800);
INSERT INTO `race_weapons` VALUES (10, 1, 'Sniper Rifle', 0, 20, 3200);
INSERT INTO `race_weapons` VALUES (11, 1, 'Jeep', 0, 40, 5100);
INSERT INTO `race_weapons` VALUES (12, 1, 'Machine Gun', 0, 160, 16400);
INSERT INTO `race_weapons` VALUES (13, 1, 'AA Gun', 0, 640, 52400);
INSERT INTO `race_weapons` VALUES (14, 1, 'Missile Emplacement', 0, 2360, 169800);
INSERT INTO `race_weapons` VALUES (15, 2, 'Dagger', 1, 5, 1000);
INSERT INTO `race_weapons` VALUES (16, 2, 'Training Staff', 1, 10, 1800);
INSERT INTO `race_weapons` VALUES (17, 2, 'Sword', 1, 20, 3200);
INSERT INTO `race_weapons` VALUES (18, 2, 'Fighting Staff', 1, 40, 5100);
INSERT INTO `race_weapons` VALUES (19, 2, 'ppg', 1, 160, 16400);
INSERT INTO `race_weapons` VALUES (20, 2, 'Pulse Cannon', 1, 640, 52400);
INSERT INTO `race_weapons` VALUES (21, 2, 'Light Bomber', 1, 2360, 169800);
INSERT INTO `race_weapons` VALUES (22, 2, 'ppg', 0, 5, 1000);
INSERT INTO `race_weapons` VALUES (23, 2, 'Energy Rifle', 0, 10, 1800);
INSERT INTO `race_weapons` VALUES (24, 2, 'Light Transport', 0, 20, 3200);
INSERT INTO `race_weapons` VALUES (25, 2, 'Hover Tank', 0, 40, 5100);
INSERT INTO `race_weapons` VALUES (26, 2, 'Pulse Cannon', 0, 160, 16400);
INSERT INTO `race_weapons` VALUES (27, 2, 'Anti-Pulse Emplacement', 0, 640, 52400);
INSERT INTO `race_weapons` VALUES (28, 2, 'Minbari Fighter', 0, 2360, 169800);

 

Note* There is no error but they just dont show up to buy!!!

Link to comment
https://forums.phpfreaks.com/topic/86075-cant-get-weapons-to-work/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.