...

View Full Version : how to sell items in PHP



tylerbe992
12-18-2008, 09:46 PM
how do i sell items in php? like text based game items..when a user has a item it goes to users_items table but i dont know how to make it so it can be sellable and add gold to the table users when a item is sold..

so far all i have is this which shows all the items the user has...i looked at the tutorial in the admins signature but it didnt help me when it comes to something like this though...


<?php session_start();

if(isset($_SESSION['otherusername'])){

$db=mysql_connect('localhost', 'root', '');

$res=mysql_select_db('textgame',$db) or die(mysql_error());


$otherusername = $_SESSION['otherusername']; //"SELECT item FROM users_items WHERE username='".$Username."'";

$res=mysql_query($otherusername)or die(mysql_error());


while($row = mysql_fetch_assoc($res)){


echo $row['item'] . "<BR />";

}
}else{

echo "Sorry your not a member please join us!";
}

?>

Fumigator
12-18-2008, 10:06 PM
Add a "sell" link to each item. Add a function when that link is clicked to update the table where you store the player's gold total and delete the item.

tylerbe992
12-18-2008, 10:33 PM
how can i give it a sell link if its echoing out of my database?

Fumigator
12-18-2008, 10:37 PM
Um... the same way you create a link in html, like this:



<a href="sell.php">sell item</a>

tylerbe992
12-18-2008, 10:40 PM
i think where on the right track..but..how can i give a field in a table a link? i dont really get it..each item is in the database.... and i have a table called users_items that has all the items the users have..

Fumigator
12-18-2008, 10:59 PM
Use the query string in the URL to pass the unique key of the table.

For information on query strings:

http://en.wikipedia.org/wiki/Query_string

http://www.webopedia.com/TERM/Q/query_string.html

http://whn.vdhri.net/2005/10/how_to_use_the_query_string_in_php.html

tylerbe992
12-18-2008, 11:00 PM
thxs!

i'll check it out! :cool:

tylerbe992
12-19-2008, 01:52 AM
so far i got this...
any help?


<?php session_start();

if(isset($_SESSION['otherusername'])){

$db=mysql_connect('localhost', 'root', '');

$res=mysql_select_db('textgame',$db) or die(mysql_error());


$otherusername = $_SESSION['otherusername']; //"SELECT item FROM users_items WHERE username='".$Username."'";

$res=mysql_query($otherusername)or die(mysql_error());


while($row = mysql_fetch_assoc($res)){


echo '<a href="sell.php?item="' . $row['item'] . '">' . $row['item'] . "<BR />";

}
}else{

echo "Sorry your not a member please join us!";
}

?>

Fumigator
12-19-2008, 02:40 AM
Is "item" the primary key in your table? If not then you need to use that.

Make sure you create valid html; you need a closing </a> tag.

tylerbe992
12-19-2008, 12:24 PM
item is the primary key..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum