berry05 Posted January 2, 2009 Share Posted January 2, 2009 i have a script that shows a list of items in my field and echos out onto a webpage..there linkable and when i hover each of them it says /sell.php?item= im trying to make it so when a user clicks on the item it sells the item and updates there gold count... any help. Quote Link to comment https://forums.phpfreaks.com/topic/139243-how-to-update-database-by-clicking-link/ Share on other sites More sharing options...
Maq Posted January 2, 2009 Share Posted January 2, 2009 Do it in sell.php: $item = $_GET['item']; UPDATE table SET item_count = item_count - 1 WHERE item = $item You need to give more information... Quote Link to comment https://forums.phpfreaks.com/topic/139243-how-to-update-database-by-clicking-link/#findComment-728337 Share on other sites More sharing options...
berry05 Posted January 2, 2009 Author Share Posted January 2, 2009 ok.. i did this.. if ( $row == "hoe" ) { but i'll try your thing thxs! Quote Link to comment https://forums.phpfreaks.com/topic/139243-how-to-update-database-by-clicking-link/#findComment-728340 Share on other sites More sharing options...
Maq Posted January 2, 2009 Share Posted January 2, 2009 ok.. i did this.. if ( $row == "hoe" ) { but i'll try your thing thxs! Sorry, I'm not sure what that is... You may need to post more relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/139243-how-to-update-database-by-clicking-link/#findComment-728344 Share on other sites More sharing options...
berry05 Posted January 2, 2009 Author Share Posted January 2, 2009 sell.php code... <?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 />"; if ( $row == "hoe" ) { echo "Your name is someguy!<br />"; } } }else{ echo "Sorry your not a member please join us!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/139243-how-to-update-database-by-clicking-link/#findComment-728351 Share on other sites More sharing options...
Maq Posted January 2, 2009 Share Posted January 2, 2009 username='".$Username."'"; Where do you get $Username from? and why are you storing queries in sessions...? Also, look at your link (assuming they are id's): echo ' So if $row['item'] is 65 then it would be: www.yoursite.com/sell.php?item=65 In your script you should check to see if item isset and if it is delete it: if(isset($_GET['item'])) { $item = $_GET['item']; $sql = "DELETE FROM table WHERE item = '$item'"; echo $sql; mysql_query($sql) or die(mysql_error()); } Quote Link to comment https://forums.phpfreaks.com/topic/139243-how-to-update-database-by-clicking-link/#findComment-728374 Share on other sites More sharing options...
berry05 Posted January 2, 2009 Author Share Posted January 2, 2009 ok thxs...i'll try something like that! Quote Link to comment https://forums.phpfreaks.com/topic/139243-how-to-update-database-by-clicking-link/#findComment-728389 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.