Jump to content
MakeWebGames

edit item problem with admin.php


Snatchy
 Share

Recommended Posts

ok well i'm just going to post the code for this one. On my items table i have added a couple of columns for buying and selling items with crystals. had that working fine and then added a column for item pics. Now when i go to edit an item it comes up with this....

Column count doesn't match value count at row 1 and deletes the item that i am trying to edit. I have tryed chopping and changing a few things to get it back working again but with no success. here is my edit item code from admin.php.

 

print "Editing Item
You can edit any aspect of this item.


Item: ".item_dropdown($c,'item')."

";
}
function edit_item_form()
{
global $ir,$c,$h;
$d=mysql_query("SELECT * FROM items WHERE itmid={$_POST['item']}",$c);
$itemi=mysql_fetch_array($d);
$f=mysql_query("SELECT * FROM food WHERE item_id={$_POST['item']}",$c);
if(mysql_num_rows($f) > 0)
{
$a=mysql_fetch_array($f);
$energy=$a['energy'];
}
else
{
$energy=1;
}
$f=mysql_query("SELECT * FROM medical WHERE item_id={$_POST['item']}",$c);
if(mysql_num_rows($f) > 0)
{
$a=mysql_fetch_array($f);
$health=$a['health'];
}
else
{
$health=10;
}
$f=mysql_query("SELECT * FROM weapons WHERE item_id={$_POST['item']}",$c);
if(mysql_num_rows($f) > 0)
{
$a=mysql_fetch_array($f);
$damage=$a['damage'];
}
else
{
$damage=1;
}
$f=mysql_query("SELECT * FROM armour WHERE item_ID={$_POST['item']}",$c);
if(mysql_num_rows($f) > 0)
{
$a=mysql_fetch_array($f);
$def=$a['Defence'];
}
else
{
$def=10;
}
print "Editing Item


Item Name: 

Item Desc.: 

Item Type: ".itemtype_dropdown($c,'itmtype',$itemi['itmtype'])."

Item Buyable: if ($itemi['itmbuyable']) { print " checked='checked'"; }
print " />

Item Price: 

Item Sell Value: 


Make Sure You put a value in both of the nugget price boxes or item will delete

Item Nugget Price : 

Item Nugget Sell Price : 

[b]Specialized[/b]

Item Energy Regen (food only): 

Item Health Regen (medical only): 

Power (weapons only): 

Damage Off (armor only): 


";
}
function edit_item_sub()
{
global $ir,$c,$h,$userid;


if(!isset($_POST['itmname'])|| !isset($_POST['itmtype'])||  !isset($_POST['itmname']) || !isset($_POST['itmdesc'])  || !isset($_POST['itmbuyprice'])|| !isset($_POST['itmnugbuy'])|| !isset($_POST['itmsellprice']) || !isset($_POST['itmnugsell'])||  !isset($_POST['itmbuyable']))
{
print "You missed one or more of the fields. Please go back and try again.

[url='admin.php?action=edititem']> Back[/url]";
$h->endpage();
exit;
}
$itmname=mysql_escape($_POST['itmname']);
$itmdesc=mysql_escape($_POST['itmdesc']);

if($_POST['itmbuyable'] == 'on') { $itmbuy=1; } else { $itmbuy=0; }
mysql_query("DELETE FROM items WHERE itmid={$_POST['itmid']}",$c);
mysql_query("DELETE FROM food WHERE item_id={$_POST['itmid']}",$c);
mysql_query("DELETE FROM weapons WHERE item_id={$_POST['itmid']}",$c);
mysql_query("DELETE FROM medical WHERE item_id={$_POST['itmid']}",$c);
mysql_query("DELETE FROM armour WHERE item_ID={$_POST['itmid']}",$c);

$m=mysql_query("INSERT INTO items VALUES('{$_POST['itmid']}',{$_POST['itmtype']},'$itmname','$itmdesc',{$_POST['itmbuyprice']},{$_POST['itmnugbuy']},{$_POST['itmsellprice']},{$_POST['itmnugsell']},'$itmbuy')",$c) or die(mysql_error());
if($_POST['itmtype'] == 1)
{
mysql_query("INSERT INTO food VALUES({$_POST['itmid']},{$_POST['energy']})",$c) or die(mysql_error());
}
if($_POST['itmtype'] == 5)
{
mysql_query("INSERT INTO medical VALUES({$_POST['itmid']},{$_POST['health']})",$c) or die(mysql_error());
}
if($_POST['itmtype'] == 3 || $_POST['itmtype'] == 4)
{
mysql_query("INSERT INTO weapons VALUES({$_POST['itmid']},{$_POST['damage']})",$c) or die(mysql_error());
}
if($_POST['itmtype'] == 7)
{
$i=mysql_insert_id();
mysql_query("INSERT INTO armour VALUES({$_POST['itmid']} ,{$_POST['Defence']})",$c) or die(mysql_error());
}

print "The {$_POST['itmname']} Item was edited successfully.";
}

 

Really really hope someone can shed some light on this as I am more than stuck with it!!!

Cheers

Snatchy

Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

 Share

×
×
  • Create New...