in the below code i loading items in using mysql_fetch_array but when i go to run the code i get this error- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home2/ronares/public_html/actions/armoury.php on line 96
it can load the items in, but when i go to manipulate the code, its when this error comes up. i have put comments in where the code starts to fail
<?
session_start();
(!defined('')) ? die : '';
(!isset($_SESSION['user_id'])) ? redirect('index.php?mode=login') : '';
if (!isset($HTTP_POST_VARS['this_mode']))
{
$set = (isset($HTTP_GET_VARS['set'])) ? $HTTP_GET_VARS['set'] : '';
$aresult = mysql_query("SELECT * FROM armoury
WHERE weapon_type='attack'");
$dresult = mysql_query("SELECT * FROM armoury
WHERE weapon_type ='defence'");
if ($dresult)
{
echo'dresult pass';
}else{
echo'dresult fail';
}
if ($dresult)
{
echo'aresult pass';
}else{
echo'aresult fail';
}
$result=mysql_query("SELECT * FROM armoury
ORDER BY weapon_type ASC");
echo '<table width="95%" cellpadding="0" cellspacing="0" border="0">
<tr>
<td align="center"><b>Weapon</b></td>
<td align="center"><b>Type</b></td>
<td align="center"><b>Cost</b></td>
<td align="center"><b>Strength</b></td>
</tr>
<form action="index.php?mode=armoury" method="POST">';
while ($armoury = mysql_fetch_array($aresult))
{
echo '<tr>
<td align="center">'.$armoury['weapon_name'].'</td>
<td align="center">'.$armoury['weapon_type'].'</td>
<td align="center">'.$armoury['weapon_cost'].'</td>
<td align="center">'.$armoury['weapon_strength'].'</td>
<td align="center">
aquantity: <input type="integer" name="Quantity" size="10" name="quantity" />:<br />
<input type="hidden" name="this_mode" value="true" />
<br />
</tr>';
}
echo '<input type="submit" value="Buy" /></form>';
}
//////////this code here seems to be the sourceof the error
//////////i know it is wrong, i need a loop to run through it i think, i asked about this in another thread
/////////would fixing that, using a loop through it so individual items can be referenced fix the error?
else if (isset($HTTP_POST_VARS['this_mode']))
{
$aquantity = (isset($HTTP_POST_VARS['aquantity'])) ? intval($HTTP_POST_VARS['aquantity']) : '';
$dquantity = (isset($HTTP_POST_VARS['dquantity'])) ? intval($HTTP_POST_VARS['dquantity']) : '';
$user = mysql_query("SELECT * FROM users
WHERE user_id = '".$_SESSION['user_id']."'");
$user = mysql_fetch_assoc($user);
If( $aquantity > 0)
{
$cost=($armoury['weapon_cost']*$armoury['aquantity']);
if ($user['user_gold'] >= $cost)
{
$apurchase = mysql_query("INSERT INTO `user_armoury` VALUES ('".$user_id."','".$user_armoury['weapon_name']."','".$user_armoury['weapon_type']."','".$user_armoury['weapon_strength']."','".$aquantity."' '')");
if ($apurchase)
{
$user_attack= mysql_query("UPDATE users
SET user_attack_rating ='".$user_attack_rating+$weapon_strength*$aquantity*$user_army_size."'
WHERE user_id = '".$_SESSION['user_id']."'");
if ($user_attack)
{
echo'attack updated';
}else{
echo'attack failed';
}
$user_gold_update= mysql_query(" UPDATE users
SET user_gold='".$user_gold-$cost."'
WHERE user_id='".$_SESSION['user_id']."'");
if($user_gold_update)
{
echo'gold updated';
}else{
echo'gold failed';
}
echo 'Purchase Successful!';
timed_redirect('index.php?mode=armoury', 5);
}else {
echo 'purchase failed';
}
}else{
echo'not enough gold';
}
}
while ($darmoury = mysql_fetch_array($dresult))
{
echo '<tr>
<td align="center">'.$darmoury['weapon_name'].'</td>
<td align="center">'.$darmoury['weapon_type'].'</td>
<td align="center">'.$darmoury['weapon_cost'].'</td>
<td align="center">'.$darmoury['weapon_strength'].'</td>
<td align="center"><form method="POST">
dquantity: <input type="integer" name="Quantity" size="10"name="quantity" />:<br />
</form><br />
</tr>';
}
$dquantity = (isset($HTTP_POST_VARS['dquantity'])) ? intval($HTTP_POST_VARS['dquantity']) : '';
If( $dquantity > 0)
{
$cost=($armoury['weapon_cost']*$armoury['dquantity']);
if ($user['user_gold'] >= $cost)
{
$dpurchase = mysql_query("INSERT INTO `user_armoury` VALUES ('".$user_id."','".$user_armoury['weapon_name']."','".$user_armoury['weapon_type']."','".$user_armoury['weapon_strength']."','".$aquantity."' )");
if ($dpurchase)
{
$user_defence= mysql_query("UPDATE users
SET user_defence_rating ='".$user_defence_rating+$weapon_strength*$dquantity*$user_army_size."';
WHERE user_id = '".$_SESSION['user_id']."'");
if ($user_defence)
{
echo'defence updated';
}else{
echo'defence failed';
}
$user_gold_update= mysql_query( "UPDATE users SET user_gold='".$user_gold-$cost."'
WHERE user_id='".$_SESSION['user_id']."'");
if($user_gold_update)
{
echo'gold updated';
}else{
echo'gold failed';
}
echo 'Purchase Successful!';
timed_redirect('index.php?mode=armoury', 5);
}else {
echo 'purchase failed';
}
}else{
echo'not enough gold';
}
}
}
?>