Jump to content

Getting variable data HELP!


twilitegxa

Recommended Posts

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.