Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/139243-how-to-update-database-by-clicking-link/
Share on other sites

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!";
}


?>

 

 

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());
}

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.