<?php
session_start(); //allow sessions
require("config.php"); //get configuration
if($logged['username']){ //if the user is logged in
switch($_GET['page']){ //start page grabbing
default: //default
print "Welcome to the shop $logged[username]."; //welcome ^^
$get_items = mysql_query("SELECT * FROM `shop_items`"); //get all items
if(mysql_num_rows($get_items) == 0){ //check if any in db
print "Sorry, No Shop Items Available.";
}else{
while($items = mysql_fetch_array($get_items)){
if($items['staffonly'] == "True" && $logged['userlevel'] >= '4'){ //staff items :D
print "<h2>Staff Items</h2>";
print "<img src=\"$items[image]\" alt=\"$items[name]\" />
<table width=\"400\">
<tr>
<td width=\"400\" colspan=\"4\" align=\"left\" valign=\"middle\">
<b>$items[name]</b>
</td>
</tr>
<tr>
<td width=\"100\" align=\"left\" valign=\"middle\">
<b>Description</b>
</td>
<td width=\"300\" align=\"center\" valign=\"middle\">
$items[desc]
</td>
</tr>
<tr>
<td width=\"100\" align=\"left\" valign=\"middle\">
<b>Price</b>
</td>
<td width=\"300\" align=\"center\" valign=\"middle\">
$items[price] Point(s)
</td>
</tr>
<tr>
<td width=\"100\" align=\"left\" valign=\"middle\">
<b>Quantity</b>
</td>
<td width=\"300\" align=\"center\" valign=\"middle\">
$items[quantity]
</td>
</tr>
<tr>
<td width=\"100\" align=\"left\" valign=\"middle\">
</td>
<td width=\"300\" align=\"center\" valign=\"middle\">
<a href=\"shop.php?page=verify&item=$items[id]\">Buy</a>
</td>
</table>"; //print item data
}elseif($items['staffonly'] == "True" && $logged['userlevel'] < '4'){
//nothing here cause admins wont be able to see it ;(
}else{ //not an admin and item aint staff only
print "<img src=\"$items[image]\" alt=\"$items[name]\" />
<table width=\"400\">
<tr>
<td width=\"400\" colspan=\"4\" align=\"left\" valign=\"middle\">
<b>$items[name]</b>
</td>
</tr>
<tr>
<td width=\"100\" align=\"left\" valign=\"middle\">
<b>Description</b>
</td>
<td width=\"300\" align=\"center\" valign=\"middle\">
$items[desc]
</td>
</tr>
<tr>
<td width=\"100\" align=\"left\" valign=\"middle\">
<b>Price</b>
</td>
<td width=\"300\" align=\"center\" valign=\"middle\">
$items[price] Point(s)
</td>
</tr>
<tr>
<td width=\"100\" align=\"left\" valign=\"middle\">
<b>Quantity</b>
</td>
<td width=\"300\" align=\"center\" valign=\"middle\">
$items[quantity]
</td>
</tr>
<tr>
<td width=\"100\" align=\"left\" valign=\"middle\">
</td>
<td width=\"300\" align=\"center\" valign=\"middle\">
<a href=\"shop.php?page=verify&item=$items[id]\">Buy</a>
</td>
</table>"; //print item data
} //end level check >]
} //end loop for items >/
} //end item check
break; //end page
case 'verify': //verify page
$itemid = (int) addslashes($_GET['item']); //get item id
if(!$itemid){ //not set
print "<b>Error</b>: No Item Selected.";
}else{ //is set
$check = mysql_query("SELECT * FROM `shop_items` WHERE `id` = '$itemid';"); //check with db
if(mysql_num_rows($check) == 0){ //invalid
print "<b>Error</b>: Invalid ID Selected.";
}else{ //not invalid
$item = mysql_fetch_array($check); //array data
print "Are you sure you want to purchase $item[name]?<br> <a href='shop.php?page=purchase&item=$itemid'>Yes</a> - <a href='shop.php'>No</a>"; //ask if they reall want to buy it.
} //end invalid check
} //end general check
break;
case 'purchase': //purchase the item ;)
$itemid = (int) addslashes($_GET['item']); //item id
if(!$itemid){ //no id found
print "<b>Error</b>: No Item Selected.";
}else{ //was found
$check = mysql_query("SELECT * FROM `shop_items` WHERE `id` = '$itemid';"); //check with db
if(mysql_num_rows($check) == 0){ //not found
print "<b>Error</b>: Invalid ID Selected.";
}else{ //found
$item = mysql_fetch_array($check); //array data
$users_items = mysql_query("SELECT * FROM `user_shop_items` WHERE `name` = '$item[name]' AND `owner` = '$logged[username]';"); //get current users items
$array_items = mysql_fetch_array($users_items); //array those items
if(mysql_num_rows($users_items) == 1){ //if its there :O
if($logged['points'] < $item['price']){ //check points
print "<b>Error</b>: You Don't Have Enough Points!"; //not enough
}else{
//has enough
$new_quantity = ($array_items['quantity'] + 1); //new quantity
$update = mysql_query("UPDATE `user_shop_items` SET `quantity` = '$new_quantity' WHERE `owner` = '$logged[username]' AND `name` = '$item[name]'"); //update it ;)
$new_points = ($logged['points'] - $item['price']); //new points
$update2 = mysql_query("UPDATE `members` SET `points` = '$new_points' WHERE `username` = '$logged[username]';"); //update them
print "You Have Bought 1 $item[name]."; //give them what they wanted ;)
} //end point check
}else{
if($logged['points'] < $item['price']){
print "<b>Error</b>: You Don't Have Enough Points!";
}else{
$insert = mysql_query("INSERT INTO `user_shop_items` (`name`,`image`,`owner`,`quantity`) VALUES ('$item[name]','$item[image]','$logged[username]','1');"); //insert item into table
$new_points = ($logged['points'] - $item['price']);
$update2 = mysql_query("UPDATE `members` SET `points` = '$new_points' WHERE `username` = '$logged[username]';"); //update points
print "You Have Bought 1 $item[name].";
}
}
}
}
break;
}
}else{
print "<b>Error</b> You Are Not Logged In."; //not logged in
}
?>
Replace with:
but did you run the SQL?
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/dalez/public_html/site/user/shop/inventory.php on line 11
Any answers for this?
Fixes to this are on the link above.