Inventory problem

Location of the Videos
Post Reply
User avatar
GodSINt
Posts: 8
Joined: Thu Apr 01, 2010 4:41 am

Inventory problem

Post by GodSINt »

This may have been asked already and I overlooked it, but the first time I buy something from my store, it doesn't show up in my inventory until I buy something else. It takes the money and adds it to the database, just doesn't show it in inventory. also I have 2 items in my store and when i try to buy the second item, it gives me the first one..... please help. here's my code...

inventory

Code: Select all

<?php
include_once 'connect.php';
session_start();
/////make sure player is logged in//////
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br/><br/> <a href='login.php'>Login</a>";
  exit;
}
$counter = 0;
////get playerstats///

$playerinfo = "SELECT * from players where name = '$player'";
$playerinfo2 = mysql_query($playerinfo) or die("Could Not Query Players");
$playerinfo3 = mysql_fetch_array($playerinfo2);

$pid = $playerinfo3['id'];

///////pockets/////
$pockets = "SELECT * from pockets where id = '$pid'";
$pockets2 = mysql_query($pockets) or die("Could Not Query Pockets!");
$pockets3 = mysql_fetch_array($pockets2);
$pocketsid=$pockets3['id'];


 echo "<small>";
      print "<center>";
      print "<table border='0' width='70%' cellspacing='20'>";
      print "<tr><td width='25%' valign='top'>";
      print "</td>";
      print "<td valign='top' width='75%'>";
      $pocketsinfo="SELECT * from pockets where amount > 0";
      $pocketsinfo2=mysql_query($pocketsinfo) or die("could not select anything from pockets.");
      print "<table border='1' bordercolor='red' bgcolor='#ffffff'>";
      print "<tr><td>Name<font color='ffffff'>________________</td><td>Type<font color='ffffff'>______</td><td>Stat Add<font color='ffffff'>______</td><td>Amount<font color='ffffff'>______</td><td><font color='ffffff'>____________</td></tr>";



   while($pocketsinfo3=mysql_fetch_array($pocketsinfo2))
      {
      $counter = 1;
      print "<tr><td>$pocketsinfo3[name]</td><td>$pocketsinfo3[type]</td><td>$pocketsinfo3[statadd]</td><td>$pocketsinfo3[amount]</td><td><A href='usedrug.php?randid=$pocketsinfo3[randid]'>Use</td></tr>";

      }

      print "</table>";
      print "</td></tr></table>";
      print "</center>";
      echo "</small>";

    if ($counter == 0)
    {
      echo "<center>You have nothing in your pockets!</center><br/>";
      echo "<center><a href='index.php'>Go Back</a></center>";
    }
    else
    {
   echo "<center><a href='index.php'>Back</a></center>";
    }
?>
Store

Code: Select all

<?php
include_once 'connect.php';
session_start();
/////make sure player is logged in//////
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br/><br/> <a href='login.php'>Login</a>";
  exit;
}
$counter = 0;
////get playerstats///

$playerinfo = "SELECT * from players where name = '$player'";
$playerinfo2 = mysql_query($playerinfo) or die("Could Not Query Players");
$playerinfo3 = mysql_fetch_array($playerinfo2);

$playerid = $playerinfo3['id'];

///////inventory/////
$pockets = "SELECT * from pockets where id = '$playerid'";
$pockets2 = mysql_query($pockets) or die("Could Not Query Inventory!");
$pockets3 = mysql_fetch_array($pockets2);
///////////drugs//////////
$dden = "SELECT * from drugden where amount > 0";
$dden2 =mysql_query($dden) or die("could not query drugden");
$dden3 =mysql_fetch_array($dden2);


 echo "<small>";
      print "<center>";
      print "<table border='0' width='70%' cellspacing='20'>";
      print "<tr><td width='25%' valign='top'>";
      print "</td>";
      print "<td valign='top' width='75%'>";
      $ddeninfo="SELECT * from drugden where amount > 0";
      $ddeninfo2=mysql_query($ddeninfo) or die("could not select anything from the store.");
      print "<table border='1' bordercolor='red' bgcolor='#ffffff'>";
      print "<tr><td>Name<font color='ffffff'>________________</td><td>Stat Add<font color='ffffff'>______</td><td>Type<font color='ffffff'>______</td><td>Price<font color='ffffff'>______</td><td><font color='ffffff'>____________</td></tr>";
      while($ddeninfo3=mysql_fetch_array($ddeninfo2))
      {
      $counter = 1;
      print "<tr><td>$ddeninfo3[name]</td><td>$ddeninfo3[statadd]</td><td>$ddeninfo3[type]</td><td>$ddeninfo3[price]</td><td><A href='buydrug.php?randid=$ddeninfo3[randid]'>Buy Item</td></tr>";

      }

      print "</table>";
      print "</td></tr></table>";
      print "</center>";
      echo "</small>";

 if($counter==0)
 {
 echo "There is nothing in the DrugDen!";
 echo "<center><a href='index.php'>Back</a></center><br/>";
 exit;
 }

 echo "<center><a href='index.php'>Back to Safehouse</a></center><br/>";


?>
Image
User avatar
hallsofvallhalla
Site Admin
Posts: 12026
Joined: Wed Apr 22, 2009 11:29 pm

Re: Inventory problem

Post by hallsofvallhalla »

i need to see buydrug.php to see the problem, but one problem i see is you are making a extra query. remember the less queries the better. You are pulling queries for no reason. Or at least no reason I can see.

Code: Select all

///////pockets/////
$pockets = "SELECT * from pockets where id = '$pid'";
$pockets2 = mysql_query($pockets) or die("Could Not Query Pockets!");
$pockets3 = mysql_fetch_array($pockets2);
$pocketsid=$pockets3['id'];
what is this query for?
User avatar
GodSINt
Posts: 8
Joined: Thu Apr 01, 2010 4:41 am

Re: Inventory problem

Post by GodSINt »

I think the query was there because i copied and pasted from something else. the pockets is actually the inventory. here is the buydrug code

Code: Select all

<?php
include_once 'connect.php';
session_start();
/////make sure player is logged in//////
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
  $randid=$_GET['randid'];
}
else
{
  echo "Not Logged in <br/><br/> <a href='login.php'>Login</a>";
  exit;
}
////get playerstats///

$playerinfo = "SELECT * from players where name = '$player'";
$playerinfo2 = mysql_query($playerinfo) or die("Could Not Query Players");
$playerinfo3 = mysql_fetch_array($playerinfo2);

$playerid = $playerinfo3['id'];
$playermoney = $playerinfo3['money'];
///////////drugs//////////
$druginfo = "Select * from drugden where amount > 0";
$druginfo2 = mysql_query($druginfo) or die ("Could not query drugs");
$druginfo3 = mysql_fetch_array($druginfo2);

$drug = $druginfo3['name'];
$drugstatadd = $druginfo3['statadd'];
$drugtype = $druginfo3['type'];
$drugprice = $druginfo3['price'];
$drugrandid = rand(1000,999999999);

$drugbought = "INSERT into pockets(id, name, statadd, randid) VALUES ('$playerid','$drug','$drugstatadd','$drugrandid')";
mysql_query($drugbought) or die("could not put drug into pockets");

$updatemoney = $playermoney - $drugprice;
$updateplayer = "update players set money = '$updatemoney' where name = '$player'";
mysql_query($updateplayer) or die("could not update money");

echo "<center>" . $drug . " Purchased!</center><br/>";
echo "<center><a href='drugden.php'>Back to DrugDen<a/></center><br/>";
echo "<center><a href='index.php'>SafeHouse</a></center>";

?>
User avatar
GodSINt
Posts: 8
Joined: Thu Apr 01, 2010 4:41 am

Re: Inventory problem

Post by GodSINt »

Ok I have fixed the problem of not getting the item in the inventory. Don't know exactly what I did because i went through and cleaned the code up alot, but my problem where it keeps buying the same item no matter which one i select still persists. I'm gonna keep trying to locate my error on my own, but any help is appreciated.
Thanks for the effort you guys are great!
Image
Post Reply

Return to “Older Browser MMO Videos”