Hello. =] I've been having trouble understanding $_GET, (in PHP); when there's something like this: ?action=buy&itemid=1. I programmed a Shopping Cart for the website that I'm making, and when somebody clicks on the item that they'd like to purchase; (the link is: shops.php?action=buy&itemid=$itemid); the page comes up blank, and nothing happends. I have no clue what's wrong with it, and I'm becomming VERY frustrated. Does anybody know where I "messed up"? Here's the entire Shopping Cart code:
<?php
session_start();
include("config.php");
if($SESSION['username'] == "" || $SESSION['password'] == "") {
notloggedin();
}
if($SESSION['username'] != "" && $SESSION['password'] != "") {
start();
$action = $GET['action'];
$shopid = $GET['shopid'];
if($action != "buy") {
$show_query = mysql_query("SELECT FROM items WHERE shopid ='$shopid' ORDER BY itemid");
for($i=0;$i<@mysql_numrows($show_query);$i++) {
$itemid=mysql_result($show_query,$i,"itemid");
$showname=mysql_result($show_query,$i,"name");
$showimage=mysql_result($show_query,$i,"image");
$showprice=mysql_result($show_query,$i,"price");
$showamount=mysql_result($show_query,$i,"amount");
$showdescription=mysql_result($show_query,$i,"description");
$showrarity=mysql_result($show_query,$i,"rarity");
if($i%4==0) echo "<tr>";
echo "<td><center>$showname<br><a href=shops.php?action=buy><img src=../images/items/$showimage border=\"0\"></a><br>$showprice EDC<br>Amount: $showamount</center></td>";
if($i%4==2) echo "</tr>";
}
if($action == "buy") {
$items_id = $GET['itemid'];
$the_item = mysql_query("SELECT FROM items WHERE itemid='$items_id'");
while($showit = mysql_fetch_array($the_item)) {
$itemid = $showit['id'];
$itemname = $showit['name'];
$itemimage = $showit['image'];
$itemprice = $showit['price'];
$itemamount = $showit['amount'];
}
$checkamount = "$credits - $itemprice";
if($checkprice < "0") {
echo "<font size=6>Shops</font><br><br>Error!<br><br>";
$show_query = mysql_query("SELECT FROM items WHERE shopid ='$shopid' ORDER BY itemid");
for($i=0;$i<@mysql_numrows($show_query);$i++) {
$itemid=mysql_result($show_query,$i,"itemid");
$showname=mysql_result($show_query,$i,"name");
$showimage=mysql_result($show_query,$i,"image");
$showprice=mysql_result($show_query,$i,"price");
$showamount=mysql_result($show_query,$i,"amount");
$showdescription=mysql_result($show_query,$i,"description");
$showrarity=mysql_result($show_query,$i,"rarity");
if($i%4==0) echo "<tr>";
echo "<td><center>$showname<br><a href=shops.php&action=buy&itemid=$itemid><img src=../images/items/$showimage border=\"0\"></a><br>$showprice EDC<br>Amount: $showamount</center></td>";
if($i%4==2) echo "</tr>";
}
if($checkprice >= 0) {
$itemsid = $GET['itemsid'];
$theitem = mysql_query("SELECT FROM items WHERE itemid='$itemsid'");
while($show = mysql_fetch_array($theitem)) {
$item_id = $show['itemid'];
$item_name = $show['name'];
$item_image = $show['image'];
$item_price = $show['price'];
$item_amount = $show['amount'];
mysql_query("UPDATE items SET amount = '$item_amount' - 1 WHERE itemid='$item_id'");
mysql_query("INSERT INTO useritems (usename, item, location) VALUES ('$username', '$item_name', 'Inventory')");
mysql_query("UPDATE users SET credits='$credits' - '$item_price' WHERE username='$username'");
}
echo "<font size=6>Shops</font><br><br>Success! You have bought that Item for $item_price USD.<br><img src=images/items/$item_image><br><br><< <a href=shops.php?shopid=1><< Back to Shop</a> | <a href=map.php>Back to Map >></a>";
}
}
}
}
}
?>
Thank You VERY Much! =]