[Problem] Inventory/store! -Solved
Posted: Thu Jan 05, 2012 4:15 pm
				
				Sorry if I insist with topics, but on the video topic I got no answer. 
This is my code
battle.php
useitem.php  //my inventory
store.php
and buyitem.php
There are severals problems.
1. When I want to fight, I can disply player and monster status, I can battle, but there are some errors:
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 30
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 35
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 36
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 37
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 38
2. I can buy ONE item from the store, but than if I buy the 2nd, it won't add/display in the inventory table, nor in the table data base. The error is on mysql_query() or die(Could not insert item into inventory).
I get the message "Could not insert item into inventory" when I want to buy another item. If I delete the first one, then I can buy 1 item, but the 2nd doesn't add, query failed.
3. When I use items (potions), my stats don't update
4. If my inventory is empty and I click the "Go Back button" I get errors:
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 30
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 35
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 36
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 37
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 38
Could not get creature stats (mysql_query() failed)
I hope you can help me, and again I am sorry for opening this 2nd topic. Thank you.
			This is my code
battle.php
Code: Select all
<?
require_once('config.php');
if (isset($_SESSION['username']))
{
	$player = $_SESSION['username'];
} else
	{
		echo "You are not logged in. <a href='../login.html'>Click</a> to log in";
		exit;
	}
$info = "SELECT * FROM `game`.`users` where username = '$player'";
$info2 = mysql_query($info) or die ("Could not get player stats"); 
$info3 = mysql_fetch_array($info2);
$playhp = $info3['hpoints'];
$playattack = $info3['attack'];
$playdefense = $info3['defense'];
/*--------------------------RANDOM ID----------------------*/
if (isset($_GET['randid']))
	{
		$randid = $_GET['randid'];
		$iteminfo = "SELECT * from inventory where randid='$randid'";
		$iteminfo2 = mysql_query($iteminfo) or die ("Could not get item random id");
		$iteminfo3 = mysql_fetch_array($iteminfo2);
	}
	if ($iteminfo3['name'])
		{
			
		} else
			{
				$name = $iteminfo3['name'];
				$stats = $iteminfo3['stats'];
				$statadd = $iteminfo3['statadd'];
				$type = $iteminfo3['type'];
				if ($type == "healing")
					{
						$newhp = $statadd + $playhp;
						
						if ($newhp > $info3['maxhp'])
							{
								$newhp = $info3['maxhp'];
							}
						$updateplayer = "UPDATE users set hpoints = '$newhp' where username = '$player'";
						mysql_query($updateplayer) or die ("Could not update player HPoints");
						
						$updateitem = "DELETE from inventory where name = '$name' AND randid = '$randid' limit 1";
						mysql_query($updateitem) or die ("Could not delete item");
						
						$playhp = $newhp;
						echo $name. "used and recovered ".$statadd." HP.<br>";
					}
			}
if (isset($_GET['creature']))
	{
		$creature = $_GET['creature'];
		$cinfo = "SELECT *from creatures where name = '$creature'";
		$cinfo2 = mysql_query($cinfo) or die ("Could not get creature stats");
		$cinfo3 = mysql_fetch_array($cinfo2);
	} else
		{
			$cinfo = "SELECT *from creatures order by rand() limit 1";
			$cinfo2 = mysql_query($cinfo) or die ("Could not get creature stats");
			$cinfo3 = mysql_fetch_array($cinfo2);
		}
		
$creature = $cinfo3['name'];
$chp = $cinfo3['hpoints'];
$cattack = $cinfo3['attack'];
$cdefense = $cinfo3['defense'];
/*---------------------------PLAYER INFO----------------------*/
echo "<b>".$info3['username'] ."</b>, lvl ".$info3['level']."<br>";
echo "HP: " . $playhp ."<br>";
echo "Attack: " . $playattack ."<br>";
echo "Defense: " . $playdefense ."<br><br><hr>";
/*---------------------------CREATURE INFO---------------------*/
echo "<b>". $cinfo3['name'] ."</b>, lvl ".$cinfo3['level']."<br>";
echo "HP: " . $chp ."<br>";
echo "Attack: " . $cattack ."<br>";
echo "Defense: " . $cdefense ."<br><br>";
echo "<a href='attack.php?creature=$creature'>Attack!</a>";
echo "<br><a href='useitem.php?creature=$creature'>Use Item!</a>";
echo "<br><a href='store.php?creature=$creature'>Go To Store!</a>";
?>Code: Select all
<?
require_once("config.php");
if (isset($_SESSION['username']))
{
	$player = $_SESSION['username'];
	
} else
	{
		echo "You are not logged in. <a href='../login.html'>Click</a> to log in";
		exit;
	}
	$creature = $_GET['creature'];
	
$info = "SELECT * FROM users where username='$player'";
$info2 = mysql_query($info) or die ("Could not get player stats"); 
$info3 = mysql_fetch_array($info2);
$playerid = $info3['id'];
//echo $player." id is".$playerid."!<br>";
$counter = 0;
echo "<small>";
	echo "<center>";
	echo "<table border='0' width='70' cellspacing='20'>";
	echo "<tr><td width='25%' valign='top'></td>";
	echo "<td valign='top' width='75%'>";
	$invinfo = "SELECT * from inventory where id = '$playerid'";
	$invinfo2 = mysql_query($invinfo) or die ("Could not select player invntory");
	echo "<table border='1' bordercolor='#ccc' bgcolor='#ffffff'";
	echo "<tr><td>Name<font color='ffffff'>__________________</font></td><td>Stat<font color='ffffff'>_______</td><td>Stat Add<font color='ffffff'>_______</td><td>Type<font color='ffffff'>______________</td><td><font color='ffffff'></td><td>";
	while ($invinfo3=mysql_fetch_array($invinfo2))
	{
		echo "<tr><td>$invinfo3[name]</td><td>$invinfo3[stats]</td><td>$invinfo3[statadd]</td><td>$invinfo3[type]</td><td><a href='battle.php?randid=$invinfo[randid]&creature=$creature'>Use Item</td></tr>";
		$counter = 1;
	}
	
	echo "</table></td></tr></table></small>";
	
	if ($counter == 0)
	{
		echo "<center>You're inventory is empty!<br>";
		echo "<a href=battle.php?creature='$creature'>Go Back..</center>";
		exit;
	}
	
	echo "<a href=battle.php?creature='$creature'>Go Back..</center>";
?>Code: Select all
<?
require_once("config.php");
if (isset($_SESSION['username']))
{
	$player = $_SESSION['username'];
	
} else
	{
		echo "You are not logged in. <a href='../login.html'>Click</a> to log in";
		exit;
	}
	$creature = $_GET['creature'];
	$counter = 0;
	
	$info = "SELECT * from users where username = '$player'";
	$info2 = mysql_query($info) or die ("Could not select player");
	$info3 = mysql_fetch_array($info2);
	echo "<small>";
	echo "<center>";
	echo "<table border='0' width='70' cellspacing='20'>";
	echo "<tr><td width='25%' valign='top'></td>";
	echo "<td valign='top' width='75%'>";
	$storeinfo = "SELECT * from store where amount > 0";
	$storeinfo2 = mysql_query($storeinfo) or die ("Could not select anything from store");
	echo "<table border='1' bordercolor='#ccc' bgcolor='#ffffff'";
	echo "<tr><td>Name<font color='ffffff'>__________________</font></td><td>Stat<font color='ffffff'>_______</td><td>Stat Add<font color='ffffff'>_______</td><td>Price<font color='ffffff'>______________</td><td><font color='ffffff'></td><td>";
	while ($storeinfo3 = mysql_fetch_array($storeinfo2))
	{
		echo "<tr><td>$storeinfo3[name]</td><td>$storeinfo3[stats]</td><td>$storeinfo3[statadd]</td><td>$storeinfo3[price]</td><td><a href='buyitem.php?randid=$storeinfo3[randid]&creature=$creature'>Buy Item</td></tr>";
		$counter = 1;
	}
	echo "</table></td></tr></table></small>";
	
	if ($counter == 0)
	{
		echo "<center>Store is empty!<br>";
		echo "<a href=battle.php?creature='$creature'>Go Back..</center>";
		exit;
	}
	
	echo "<a href=battle.php?creature='$creature'>Go Back..</center>";
?>Code: Select all
<?
require_once('config.php');
if (isset($_SESSION['username']))
{
	$player  =  $_SESSION['username'];
} else
	{
		echo "You are not logged in. <a href = '../login.html'>Click</a> to log in";
		exit;
	}
  $creature  =  $_GET['creature'];
  $randid  =  $_GET['randid'];
$info  =  "SELECT * from users where username = '$player'";
$info2 = mysql_query($info) or die("Could not get player stats!");
$info3 = mysql_fetch_array($info2);
$playerid  =  $info3['id'];
$iteminfo = "SELECT * from store where randid = '$randid'";
$iteminfo2 = mysql_query($iteminfo) or die("Could not get item stats!");
$iteminfo3 = mysql_fetch_array($iteminfo2);
$name  =  $iteminfo3['name'];
$stats  =  $iteminfo3['stats'];
$statadd  =  $iteminfo3['statadd'];
$type  =  $iteminfo3['type'];
$randid2  =  rand(1000,999999999);
$itembought  =  "INSERT into inventory(id, name, stats, statadd, randid,type) VALUES ('$playerid','$name','$stats','$statadd','$randid2','$type')";
mysql_query($itembought) or die("Could not insert item into inventory");
echo $name . " Purchased";
 echo "<center><a href = 'battle.php?creature = $creature'>Go Back</center>";
  
  ?>1. When I want to fight, I can disply player and monster status, I can battle, but there are some errors:
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 30
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 35
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 36
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 37
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 38
2. I can buy ONE item from the store, but than if I buy the 2nd, it won't add/display in the inventory table, nor in the table data base. The error is on mysql_query() or die(Could not insert item into inventory).
I get the message "Could not insert item into inventory" when I want to buy another item. If I delete the first one, then I can buy 1 item, but the 2nd doesn't add, query failed.
3. When I use items (potions), my stats don't update
4. If my inventory is empty and I click the "Go Back button" I get errors:
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 30
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 35
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 36
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 37
Notice: Undefined variable: iteminfo3 in C:\xampp\htdocs\game\php\battle.php on line 38
Could not get creature stats (mysql_query() failed)
I hope you can help me, and again I am sorry for opening this 2nd topic. Thank you.