Simple Inventory Script

Forum
Last Post
Threads / Messages

The Codfin Keeper

A Codfin draws near!
Member
Joined
Jan 21, 2011
Messages
91
Points
0
Location
Either CT or the Slug's house
Mysidian Dollar
7,522
NOTE: This is just a simple inventory addon/mod, not anything too fancy.

First, log in to phpMyAdmin or wherever you can manage your database and add a new table with the following:


id, int(11), not null, auto_increment
owner, varchar(40), latin1_general_ci, yes (NULL)
itemtype, varchar(40), latin1_general_ci, yes (NULL)
imgurl, varchar(120), latin1_general_ci, yes (NULL)

This allows for ID search if such a mod is made, the owner, what kind of item it is, and its image's URL.

Now create a new page with this script.

PHP:
<?php

// **********************************************************************
// Mysidia Adoptables Script: blank.php, the standard dev file
// Copyright 2011 Mysidia Adoptables staff team
// For help and support: http://www.mysidiaadoptables.com/forum/
//
// Redistribution prohibited without written permission
// **********************************************************************


// Wake the sleeping giant

// **********************************************************************
// Basic Configuration Info
// **********************************************************************

include("inc/functions.php");
include("inc/config.php");

$themeurl = grabanysetting("themeurl");

// **********************************************************************
// Define our top links by calling getlinks()
// **********************************************************************

$links = getlinks();

// **********************************************************************
// Define our ads by calling getads()
// **********************************************************************

$ads = getads("any");

// **********************************************************************
// Grab any dynamic article content from the content table
// **********************************************************************

$pagecontent = getsitecontent("index");
$article_title = $pagecontent[title];
$article_content = $pagecontent[content];
$article_content = nl2br($article_content);

// **********************************************************************
// Grab any settings that we will need for the current page from the DB
// **********************************************************************

$browsertitle = grabanysetting("browsertitle");
$sitename = grabanysetting("sitename");
$slogan = grabanysetting("slogan");

// **********************************************************************
// Check and see if the user is logged in to the site
// **********************************************************************

$loginstatus = logincheck();
$isloggedin = $loginstatus[loginstatus];
$loggedinname = $loginstatus[username];

// **********************************************************************
// End Prepwork - Output the page to the user
// **********************************************************************

$article_title = "Your Inventory";

if ($isloggedin == "yes") {
$article_content = "Here you can see a list of items that you have collected.<table width='500' border='2'>
<tr>
    <td width='200'><strong>Picture:</strong></td>
    <td width='230'><strong>Item Type: </strong></td>
    <td width='70'><strong>ID Number:</strong></td>
</tr>";
 
$query = "SELECT * FROM ".$prefix."useritems WHERE Owner = '$loggedinname'";
$result = mysql_query($query);
$num = mysql_numrows($result);

$i=0;
while ($i < $num) {

$iid=@mysql_result($result,$i,"ID");
$object=@mysql_result($result,$i,"Item");
$url=@mysql_result($result,$i,"imageurl");


$article_content = $article_content."<tr>
    <td><center><img src='".$url."'></center></td>
    <td><center>".$object."</center></td>
    <td><center>".$iid."</center></td>
  </tr>";

unset($iid);
unset($object);

$i = $i + 1;
}
$article_content = $article_content."</table>";

}
else {

$article_content = "You must be logged in to view items.";

}
// **********************************************************************
// Begin Template Definition
// **********************************************************************

//Define our current theme
$file = $themeurl;

// Do the template changes and echo the ready template
$template = file_get_contents($file);

$template = replace(':ARTICLETITLE:',$article_title,$template);
$template = replace(':ARTICLECONTENT:',$article_content,$template);
$template = replace(':ARTICLEDATE:',$article_date,$template);

$template = replace(':BROWSERTITLE:',$browsertitle,$template);
$template = replace(':SITENAME:',$sitename,$template);

//Define our links
$template = replace(':LINKSBAR:',$links,$template);

//Get the content for the side bar...

$sidebar = getsidebar();
$template = replace(':SIDEFEED:',$sidebar,$template);

//Get the ad content...
$template = replace(':ADS:',$ads,$template);

//Get the slogan info
$template = replace(':SLOGAN:',$slogan,$template);


echo $template;

// **********************************************************************
// End Template Definition
// **********************************************************************



?>

That is the page for users to view their inventory. You may edit the text on the page and code if you add more parameters to items, and this page's script can be used in other areas, such as the little inventory box on TCKAS' front page.

Now, in order for users to hold items, they need them to begin with, correct? To make a page (or part of a page) hand out an item to the current user, add this script where needed:

PHP:
is ($isloggedin == "yes"){
$itemurl = "URL_OF_IMAGE_GOES_HERE";
mysql_query("INSERT INTO ".$prefix."useritems VALUES ('','$loggedinname','NAME_OF_ITEM_GOES_HERE','$itemurl')");
}
else{
$article_content = $article_content."You must be logged in to receive this item.";
}

And it adds the item into the table of users' items with the logged in user (doesn't add the item if the recipient is a guest), the item's name, and the image URL, which displays on the inventory page or wherever the inventory shows.

If I missed anything, please tell me, as well as if you find any glitches. This is my first major modification, so it can be improved. So give me feedback :colonu:

EDIT: btw, if you need a replacement image or temporary image for an item, you may use what I made;

74598913.png

Code:
http://img37.imageshack.us/img37/1815/74598913.png
 
Last edited:
I'm having a problem with this script, it's not showing up and telling me I have an error on line 113, which is the following;

$template = file_get_contents($file); It's saying it can't find the file?
 
Well this script is incompatible with Mys v1.2.x, you will have to make slight modifications for it to work. Simply take out the site information at the beginning and template definition at the bottom of this script file and it should work just fine.
 
I tried doing that and it looked okay, but then it kept saying I wasn't logged in every time I visited. Someone helped me edit the script a little, i'll try again.
 
I tried doing that and it looked okay, but then it kept saying I wasn't logged in every time I visited. Someone helped me edit the script a little, i'll try again.
Well, did you remember to include the functions.php file?
 
my inventory script looks like this right now;

Code:
<?php

include("inc/functions.php");
include("inc/config.php");

//***************//
//  START SCRIPT //
//***************//

$themeurl = grabanysetting("themeurl");
$links = getlinks();
$ads = getads("any");
$pagecontent = getsitecontent("index");
$article_title = $pagecontent[title];
$article_content = $pagecontent[content];
$article_content = nl2br($article_content);

$article_title = "Your Inventory";

if ($isloggedin == "yes") {
$article_content = "Here you can see a list of items that you have collected.<table width='500' border='2'>
<tr>
    <td width='200'><strong>Picture:</strong></td>
    <td width='230'><strong>Item Type: </strong></td>
    <td width='70'><strong>ID Number:</strong></td>
</tr>";
 
$query = "SELECT * FROM ".$prefix."useritems WHERE Owner = '$loggedinname'";
$result = mysql_query($query);
$num = mysql_numrows($result);

$i=0;
while ($i < $num) {

$iid=@mysql_result($result,$i,"ID");
$object=@mysql_result($result,$i,"Item");
$url=@mysql_result($result,$i,"imageurl");


$article_content = $article_content."<tr>
    <td><center><img src='".$url."'></center></td>
    <td><center>".$object."</center></td>
    <td><center>".$iid."</center></td>
  </tr>";

unset($iid);
unset($object);

$i = $i + 1;
}
$article_content = $article_content."</table>";

}
else {

$article_content = "You must be logged in to view items.";

}
//***************//
//  OUTPUT PAGE  //
//***************//

echo showpage($article_title, $article_content, $date);

?>

the page is now showing up, but the layout is out of whack - it has large text, and it says "Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /home/gloometh/public_html/inventory.php on line 30" near the top of the page.

the page looks fine when i'm logged out though.
 
I don't know much about this mod but this should work

PHP:
<?php

include("inc/functions.php");

//***************//
//  START SCRIPT //
//***************//

$article_title = "Your Inventory";

if ($isloggedin == "yes") {
$article_content = "Here you can see a list of items that you have collected.<table width='500' border='2'>
<tr>
    <td width='200'><strong>Picture:</strong></td>
    <td width='230'><strong>Item Type: </strong></td>
    <td width='70'><strong>ID Number:</strong></td>
</tr>";
 
$query = "SELECT * FROM ".$prefix."useritems WHERE Owner = '$loggedinname'";
$result = mysql_query($query);
$num = mysql_numrows($result);

$i=0;
while ($i < $num) {

$iid=@mysql_result($result,$i,"ID");
$object=@mysql_result($result,$i,"Item");
$url=@mysql_result($result,$i,"imageurl");


$article_content = $article_content."<tr>
    <td><center><img src='".$url."'></center></td>
    <td><center>".$object."</center></td>
    <td><center>".$iid."</center></td>
  </tr>";

unset($iid);
unset($object);

$i++;
}
$article_content = $article_content."</table>";

}
else {

$article_content = "You must be logged in to view items.";

}
//***************//
//  OUTPUT PAGE  //
//***************//

echo showpage($article_title, $article_content, $date);

?>

Also, make sure the table prefix_useritems exists in the database.
 
thank you, it worked! :D I did redo the database too, just to be on the safe side, and that may have been it... now, I shall go test an item, thank you so much!

EDIT: Darn, now I'm just having trouble with the item giver thingy. D: Every time I try to test it, it gives me an error.

I'm testing on a random page;

Code:
<?php

include("inc/functions.php");

//***************//
//  START SCRIPT //
//***************//


is ($isloggedin == "yes")
$itemurl = "http://img37.imageshack.us/img37/1815/74598913.png";
mysql_query("INSERT INTO ".$prefix."useritems VALUES ('','$loggedinname','Testing X','$itemurl')");
}
else{
$article_content = $article_content."You must be logged in to receive this item.";
}  


//***************//
//  OUTPUT PAGE  //
//***************//

echo showpage($article_title, $article_content, $date);


?>

http://ratties.x10.mx/item.php

It says;

Parse error: syntax error, unexpected T_VARIABLE in /home/gloometh/public_html/item.php on line 12
 
Last edited:
This should work
PHP:
<?php

include("inc/functions.php");

//***************//
//  START SCRIPT //
//***************//


if ($isloggedin == "yes") {
$itemurl = "http://img37.imageshack.us/img37/1815/74598913.png";
mysql_query("INSERT INTO ".$prefix."useritems VALUES ('','$loggedinname','Testing X','$itemurl')");
}
else{
$article_content = $article_content."You must be logged in to receive this item.";
}  


//***************//
//  OUTPUT PAGE  //
//***************//

echo showpage($article_title, $article_content, $date);


?>

I don't think there's such a thing as 'is' function in PHP. It should be 'if'
And you forgot an opening curly bracket after the ($isloggedin == "yes")
 
well, that did work, except that the image or the name aren't showing up. The page I tested it on was blank, but blank items are showing up in my inventory. It doesn't show an image or a name, but it shows the id.

I'm sorry for all of the trouble with this... D:
 
well, that did work, except that the image or the name aren't showing up. The page I tested it on was blank, but blank items are showing up in my inventory. It doesn't show an image or a name, but it shows the id.

I'm sorry for all of the trouble with this... D:
You mean the page where users can get items is blank? Obviously, it's because the $article_content isn't defined anywhere on that page.
For the images & names that aren't showing up, it's probably because a mismatch between the column name in the table and the selected column while fetching data from the database.
 
Alright, I shall look into it later.

Sorry for the stupidity, my rat had a stroke this morning and ive been freaking out.

EDIT: I got it all worked out, thank you very, very much for your help!
 
Last edited:
The only problem I'm having now is that the name isn't showing up for some reason. The rest seems to be working fine.

Thanks - she's not getting much better, I think it's her last few days...
 

Similar threads

Users who are viewing this thread

  • Forum Contains New Posts
  • Forum Contains No New Posts

Forum statistics

Threads
4,274
Messages
33,115
Members
1,602
Latest member
BerrieMilk
BETA

Latest Threads

Latest Posts

Top