Forum Moderators: coopster
My columns are set like this
weapon armor greaves etc etc
this is my code
##Connect to User Database
$uresult = mysql_query("SELECT * FROM user_char where username = '$username'", $link) or die ("query 1: " . mysql_error());
if ($urow = mysql_fetch_array($uresult) == $sitem)
{
$resresult = mysql_query("UPDATE user_char set $item_type2 = '' where username = '$username'", $link);
echo $sitem.''.$username.''.$item_type2;
}
else
{
echo $sitem.''.$username.''.$item_type2;
}
I keep getting the else activated.
$sitem = the item name
$item_type2 = greaves or helmet etc
Thank you
$urow = mysql_fetch_array($uresult) == $sitem
extract the row to urow then compare the proper element in the array
like so
$urow = mysql_fetch_array($uresult)
if ($urow['itemname'] == $sitem) {
$resresult = mysql_query("UPDATE user_char set $item_type2 = '' where username = '$username'", $link);
echo $sitem.''.$username.''.$item_type2;
} else {
echo $sitem.''.$username.''.$item_type2;
}
though $urow['itemname'] may not be the right column name
function resell()
{
global $funds, $sell, $money, $username, $id, $link, $sitem, $username, $item_type2;
$money = $funds + $sell;
##Connect to User Database
$uresult = mysql_query("SELECT $item_type2 FROM user_char where username = '$username'", $link) or die ("query 1: " . mysql_error());
$urow = mysql_fetch_array($uresult) or die ("query 1: " . mysql_error());
if ($urow['$item_type2'] == $sitem)
{
$resresult = mysql_query("UPDATE user_char set $item_type2 = '' where username = '$username'", $link);
echo 'GOOD'.$sitem.''.$username.''.$item_type2;
}
else
{
echo 'BAD'.''.$urow[$item_type2].''.$sitem.''.$username.''.$item_type2;
index();
exit;
}
$sresult = mysql_query("UPDATE user_char set gold = '$money' where username = '$username'", $link);
$sdelete = mysql_query("DELETE FROM purchased where id = '$id' order by type asc", $link);
if ($sresult == TRUE && $sdelete == TRUE)
{
echo 'Item deleted and your gold has been updated. You now have '.$money.' gold.';
index();
}
else
{
echo 'Actions not executed';
index();
}
##End Function
}