Page 1 of 1

Store problem

Posted: Fri Apr 25, 2014 11:44 pm
by Axurr
When I go to add something into the store,It doesn't give it a randid? I went back to follow the video but idk what im missing.

store.php

Code: Select all

<?php
include_once 'connect.php';
 session_start();

if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}

  
$counter = 0;

$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

 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%'>";
      $invinfo="SELECT * from store where amount > 0";
      $invinfo2=mysql_query($invinfo) or die("could not select anything from the store.");
      print "<table border='1' bordercolor='white' bgcolor='#ffffff'>";
      print "<tr><td>Name<font color='ffffff'>________________</td><td>Stat<font color='ffffff'>______</td><td>Stat Add<font color='ffffff'>______</td><td>Type<font color='ffffff'>______</td><td>Price<font color='ffffff'>______</td></tr>";
      while($invinfo3=mysql_fetch_array($invinfo2))
      {
      $counter = 1;
      print "<tr><td>$invinfo3[name]</td><td>$invinfo3[stats]</td><td>$invinfo3[statadd]</td><td>$invinfo3[type]</td><td>$invinfo3[price]</td><td><A href='buyitem.php?randid=$invinfo3[randid]'>Buy Item</td></tr>";

      }

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

      if ($counter == 0)
      {
            echo "<center>There is nothing in the store at this time.<br>";
            echo "<a href='index.php'>Go Back</center>";
            exit;
      }
  echo "<center><a href='index.php'>NeverMind</center>";
  
  ?>
<div id="gold">
<?php
echo "<b><big><u>Gold</u></big></b><br>";
echo $playerinfo3['gold'];
?>
</div>
buyitem.php

Code: Select all

<?php
include_once 'connect.php';
 session_start();

if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}


  $randid=$_GET['randid'];

$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);

$playerid = $playerinfo3['id'];

$iteminfo="SELECT * from store where randid='$randid'";
$iteminfo2=mysql_query($iteminfo) or die("could not get item stats!");
$iteminfo3=mysql_fetch_array($iteminfo2);

if $playerinfo3['gold'] < $iteminfo3['price'])
{
 echo "You do not have enough Gold for this item!"
 echo "<center><a href='index.php'>Go Back</center>";
 exit;
}

$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 backpack");

$updateplayer="update players set gold=gold-'$playerinfo3['price']' where name='$player'";
  mysql_query($updateplayer) or die("Could not update player");

echo $name . " Purchased";
 echo "<center><a href='index.php'>Go Back</center>";
  ////did not make a - counter for item////
  
  ?>

Re: Store problem

Posted: Sat Apr 26, 2014 12:12 am
by hallsofvallhalla
did you set the data type for the randid in the table to int and give it enough characters? So in other words in the DB under the inventory table the randid field needs to be int with 11.

Re: Store problem

Posted: Sat Apr 26, 2014 12:20 am
by Axurr
store structure
Image


Inv structure
Image


Like this?

Re: Store problem

Posted: Sat Apr 26, 2014 12:39 am
by hallsofvallhalla
so everything works, no errors? It just doesnt add a randid? Which table or both? What does it put in there?

Re: Store problem

Posted: Sat Apr 26, 2014 12:42 am
by Axurr
Well it adds them just with no randid I guess but when I go and try to buy something it gives me this error


Parse error: syntax error, unexpected '$playerinfo3' (T_VARIABLE), expecting '(' in C:\wamp\www\rumwelf\buyitem.php on line 28

Re: Store problem

Posted: Sat Apr 26, 2014 1:11 am
by SpiritWebb
your line:

Code: Select all

if $playerinfo3['gold'] < $iteminfo3['price'])


Needs to be:

Code: Select all

if ($playerinfo3['gold'] < $iteminfo3['price'])

Re: Store problem

Posted: Sat Apr 26, 2014 1:21 am
by Axurr
Well now I've got another error lol

Parse error: syntax error, unexpected 'echo' (T_ECHO), expecting ',' or ';' in C:\wamp\www\rumwelf\buyitem.php on line 31

Re: Store problem

Posted: Sat Apr 26, 2014 1:24 am
by SpiritWebb
Line 30:

Code: Select all

echo "You do not have enough Gold for this item!"
Needs to be:

Code: Select all

echo "You do not have enough Gold for this item!";

Re: Store problem

Posted: Sat Apr 26, 2014 1:49 am
by Axurr
So I fixed that and was given another error :/

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in C:\wamp\www\rumwelf\buyitem.php on line 44

Re: Store problem

Posted: Sat Apr 26, 2014 1:57 am
by SpiritWebb

Code: Select all

$updateplayer="update players set gold=gold-'$playerinfo3['price']' where name='$player'";
      mysql_query($updateplayer) or die("Could not update player");
Should be

Code: Select all

$updateplayer="update players set gold='$playerinfo3['price']' where name='$player'";
      mysql_query($updateplayer) or die("Could not update player");
Make sure in the die function your putting (mysql_error()) instead of (" whatever ") so you can fully see the error as Halls has asked several times