Newbie PHP Item addition

Hi everyone :slight_smile:

I have this piece of code below that I need help with ;D

A brief description of what the code is suppose to do, it’s to create a item and stores the item in the “Items” section of the database. That works fine.

Now what I want to do is add an extra feature, when it creates the item and stores it, I also want it to also deposit that item into the user’s account “Inventory”. I am really new to php programming so this code was inherited by me. :stuck_out_tongue: I tried to add the code below in bold hoping it would do the trick but I failed miserably :’( It still creates the item and stores it in "Items’ but it does not store a copy of it in “Inventory” specifically in the session ID of the user creating the item.

If anyone can help see what I did wrong or tell me what I should add, I would truly appreciate it, I have been wrecking my brain for the past few days trying to figure out :frowning: Thanks in advance :slight_smile:

$create=1;

      if($createitem){
        if(($session['status'] == 9) || ($session['status'] == 5) || ($session['status'] == 1)){

          $name = $itemName;
          $type = $itemType;
          if($itemType2){ $type = "$itemType2 $type"; }
          $equip = $itemEquip;
          $lvl = $itemLvl;
          $avail = $itemAvail;
          $damage = $dmg;
          $heal = 0;
          $armor = $armor;
          $stamina = $stm;
          $strength = $str;
          $intellect = $int;
          $agility = $agi;
          $spirit = $spi;
          $worth = 0;
          $QTY = 0;
          if(!$session['username']){
             $user = mysql_fetch_array(mysql_query("SELECT username FROM $tab[account] WHERE id='$session[aid]';"));
             $session['username'] = $user['username'];
	 
        }
          $createdby = ucfirst($session['username']);
          mysql_query("INSERT INTO items (name,type,equip,lvl,avail,damage,heal,armor,stamina,strength,intellect,agility,spirit,worth,QTY,createdby) VALUES ('$name','$type','$equip','$lvl','$avail','$damage','$heal','$armor','$stamina','$strength','$intellect','$agility','$spirit','$worth','$QTY','$createdby');");
          [b]mysql_query("INSERT INTO inventory WHERE hid='$session[id]'(hid,name,type,equip,lvl,avail,damage,armor,stamina,strength,spirit,agility,intellect) WHERE id='$session[id]';");[/b]
          header("Location: additem.php?success=1"); die();

        }else{ $msg="You don't have permission to create or modify items."; }

[php] mysql_query(“INSERT INTO inventory WHERE hid=’$session[id]’(hid,name,type,equip,lvl,avail,damage,armor,stamina,strength,spirit,agility,intellect) WHERE id=’$session[id]’;”);[/php]

You have you insert statement wrong, it’s not proper syntax.

Take a look at this

Thanks for your reply. I appreciate it :slight_smile:

I will be honest, I did read the link you listed but I didn’t understand all of it as I just started learning recently so :frowning:

You mentioned my insert statement is wrong because of my syntax. Could you let me know what the line of code I should use with the proper syntax?

I would really appreciate it :-*

Below is your insert statement

[php] mysql_query(“INSERT INTO inventory WHERE
hid=’$session[id]’(hid,name,type,equip,lvl,avail,damage,armor,stamina,strength,spirit,agility,intellect)
WHERE id=’$session[id]’;”);[/php]

In the above statement you have 2 where clauses, with an insert statement their is no where clause.

In the link I provided, it shows the structure of one.

INSERT [LOW_PRIORITY | DELAYED | HIGH_PRIORITY] [IGNORE] [INTO] tbl_name [PARTITION (partition_name,...)] [(col_name,...)] {VALUES | VALUE} ({expr | DEFAULT},...),(...),... [ ON DUPLICATE KEY UPDATE col_name=expr [, col_name=expr] ... ]

NOW if you recoded it like this it will be more correct, but without seeing your table structure I have no way to validate if this is corrent.

[php]mysql_query(“INSERT INTO inventory (hid,name,type,equip,lvl,avail,damage,armor,stamina,strength,spirit,agility,intellect) values ($session[id], $name,$type,$equip,$lvl,$avail,$damage,$armor,$stamina,$strength,$spirit,$agility,$intellect )”) ;[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service