twilitegxa Posted March 10, 2010 Share Posted March 10, 2010 I have the following page: <?php $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); $db = mysql_select_db("smrpg", $conn) or die(mysql_error()); $location = $_GET['location']; $choice = $_GET['choice']; //ITEM SHOP if ($location == 'item_shop' && $choice == 'buy') { $get_items = "select * from shop_items where shop = 'Item'"; $get_items_res = mysql_query($get_items, $conn) or die(mysql_error()); echo "<h3>Item Shop</h3>"; echo "<form action=buy.php method=post><table border=0 cellspacing=3 cellpadding=3><th>Item</th><th>Price</th><th>Quantity</th>"; while ($show_item = mysql_fetch_array($get_items_res)) { $item = $show_item['item']; $price = $show_item['price']; echo "<tr><td>$item</td> <td align=center>$price S</td> <td><input type=text size=2 name=quantity></td> </tr>"; } echo "<tr><td colspan=3><input type=button value=Buy> <a href=location.php?location=item_shop><input type=button value=Back></a></td></tr></table></form>"; //WEAPON SHOP } else if ($location == 'weapon_shop' && $choice == 'buy') { $get_items = "select * from shop_items where shop = 'Weapon'"; $get_items_res = mysql_query($get_items, $conn) or die(mysql_error()); echo "<table border=0 cellspacing=3 cellpadding=3><th>Item</th><th>Price</th>"; while ($show_item = mysql_fetch_array($get_items_res)) { $item = $show_item['item']; $price = $show_item['price']; echo "<tr><td>$item</td><td align=center>$price S</td></tr>"; } echo "</table>"; } //get identity $get_identity = "select * from scouts where username = '".$_SESSION['userName']."' and active = '1'"; $get_identity_res = mysql_query($get_identity, $conn) or die(mysql_error()); while ($user_identity = mysql_fetch_array($get_identity_res)) { $identity = $user_identity['identity']; //gather gold $get_gold = "select * from gold where identity = '$identity'"; $get_gold_res = mysql_query($get_gold, $conn) or die(mysql_error()); while ($show_gold = mysql_fetch_array($get_gold_res)) { $gold = $show_gold['amount']; echo "<strong>Gold</strong>: $gold"; } } ?> And what I would like to do is on my buy.php page, I want to display which items they chose to buy. If they didn't put a value in the input box or if they put a zero, then I want it to show nothing. But if they typed in a value, like 1 or 2, etc, then I want it to display the items they chose and the quantity, along with a total. Here's the basic idea: <h1>Purchased Items</h1> Items you have purchased: <table> <th>Item</th> <th>Price</th> <th>Quantity</th> <th>Total</th> <tr> <td>Herb</td> <td>40 S</td> <td>5</td> <td>200 S</td> </tr> <tr> <td>Antidote</td> <td>20 S</td> <td>5</td> <td>100 S</td> </tr> <tr> <td colspan=3><strong>Total:</strong></td> <td><strong>300 S</strong></td> </tr> </table> What I need to know is, how can I get the values of each item and quantity that the user wants to buy over to the buy.php page? Is it possible to do it the way I currently have the page? Or do I have to do it another way? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted March 10, 2010 Author Share Posted March 10, 2010 I think I'm going to try it another way. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.