The problem I have is that there is a randid field in the store table, but that randid number stays the same all the time. So if someone knew the randid number for any item, then they could just type the url and get the item. This kind of makes it hard to have better items in different locations, as they could just get it in any location.
Is there a way to fix this? Here is my code to the store and to the buy_item...
store.php
Code: Select all
<?php
$counter = 0;
echo "<small>";
print "<center><br><br>";
print "<table border='0' width='95%'>";
print "<tr><td>";
print "</td>";
print "<td>";
$sql = "SELECT * FROM store WHERE amount > 0 AND location = '$stats_location'";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
print "<table cellspacing='5' style='border: 0px solid white; color: lime;' width='99%'>";
print "<tr align='left'><td><u>Name</u></td><td><u>Stat</u></td><td><u>Stat Add</u></td><td><u>Type</u></td><td><u>Price</u></td><td></td></tr>";
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
$counter = 1;
print "<tr align='left'><td>$row[name]</td><td>$row[stat]</td><td>$row[statadd]</td><td>$row[type]</td><td>$row[price]</td><td><A href='buy_item.php?randid=$row[randid]'><font color='red'>Buy Item</font></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 because we are broke as hell.<br>";
exit;
}
?>
Code: Select all
<?php
$id = $_SESSION['userid'];
$randid=$_GET['randid'];
$sql = "SELECT * FROM store WHERE randid='$randid'";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
if ($stats_gold < $row['price'])
{
echo "You do not have enough Gold for this purchase!";
echo "<center><a href='index.php'>Go Back</center>";
exit;
}
}
$id = $_SESSION['userid'];
$randid=$_GET['randid'];
$sql = "SELECT * FROM store WHERE randid='$randid'";
$user_query = mysqli_query($db_conx, $sql);
$numrows = mysqli_num_rows($user_query);
while ($row = mysqli_fetch_array($user_query, MYSQLI_ASSOC)) {
$name = $row['name'];
$stats1 = $row['stat'];
$statadd = $row['statadd'];
$type = $row['type'];
$price = $row['price'];
$randid2 = rand(1000,999999999);
$sql = "INSERT INTO inventory (id, name, stats, statadd, randid,type) VALUES ('$id','$name','$stats1',$statadd,$randid2,'$type')";
$query = mysqli_query($db_conx, $sql);
$sql = "UPDATE stats set gold=gold-'$price' WHERE id = '$_SESSION[userid]'";
$query = mysqli_query($db_conx, $sql);
echo "<br><br><span id='errormess'><big><center><font color='lime'> $name Purchased</center><br></span></big></font>";
}
?>