how to delete row from table what i wanna?[solved]

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
Zoo
Posts: 21
Joined: Tue Apr 17, 2012 6:38 pm

how to delete row from table what i wanna?[solved]

Post by Zoo »

Hey, i tried make selling system, but i stuck cuz always, when i pushed button sell item, this ma code sell first item in table not that what i realy wanna sell in shop..
Where i made mistake?

Code: Select all

<?php
include_once 'connect.php';
 session_start();
 include_once 'logo.php';
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<?php

if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}

$playerinfo="SELECT * FROM players WHERE name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
include_once 'statpanel.php';
?>
<div id="table">
<?php

$playerid = $playerinfo3['id'];


$iteminfo="SELECT * FROM inventory WHERE id='$playerid'";
$iteminfo2=mysql_query($iteminfo) or die("could not get item stats!");
$iteminfo3=mysql_fetch_array($iteminfo2);



$name = $iteminfo3['name'];
$sellprice = $iteminfo3['sellprice'];

$sellitem = "DELETE FROM inventory WHERE  randid = '$iteminfo3[randid]'"; // shoud be here, i cant understand why cant sell item only with this rand code//
mysql_query($sellitem) or die("could not sell item from backpack");

$updateplayer="UPDATE players SET gold=gold+'$iteminfo3[sellprice]' WHERE name='$player'";
  mysql_query($updateplayer) or die("Could not update player");

echo $name . " Sell";
 echo "<center><a href='index.php'>Go Back</center>";
  ////did not make a - counter for item////
  
  ?>
 </div>
Last edited by Zoo on Thu May 03, 2012 6:44 am, edited 1 time in total.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: how to delete row from table what i wanna?

Post by Jackolantern »

So to be sure, the problem is that the first item in the player's inventory is being removed instead of the one you wanted to remove?
The indelible lord of tl;dr
Zoo
Posts: 21
Joined: Tue Apr 17, 2012 6:38 pm

Re: how to delete row from table what i wanna?

Post by Zoo »

yes, u r correct. Image for exemple i wanna sell potion for 10 gold, but code sell for 12 gold, always first line from top.
Winawer
Posts: 180
Joined: Wed Aug 17, 2011 5:53 am

Re: how to delete row from table what i wanna?

Post by Winawer »

You're not picking the item anywhere in your code.

Code: Select all

$iteminfo="SELECT * FROM inventory WHERE id='$playerid'"; 
picks all the items in the player's inventory and should probably be something like

Code: Select all

$iteminfo="SELECT * FROM inventory WHERE id='$playerid' AND randid='".mysql_real_escape_string($_GET['randid'])."'"; 
to pick just the one item being sold.
Zoo
Posts: 21
Joined: Tue Apr 17, 2012 6:38 pm

Re: how to delete row from table what i wanna?

Post by Zoo »

wow its working! thank you very much!
Post Reply

Return to “Beginner Help and Support”