Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Aiheen aloitti: Keydet - joulukuu 20, 2013, 08:25:10 IP

Otsikko: Fixing a code snippet
Kirjoitti: Keydet - joulukuu 20, 2013, 08:25:10 IP
Hello, I'm adding an item to SMFShop. I'd ask for help over there, but it's basic enough and that forum is rarely viewed.

I am trying to just get this item to write to the database when I use it, currently goes to a blank white screen when I try to.

The first three id's are values that the database assigned the item, so I just pulled those. user_id needs to pull the member's id from the forum, but I'm not sure if it's doing that. Points spent should be 0, and the purchase date should be on use.

The database is called la_items_purchased.

Thank you in advance!

function onUse()
{
global $db_prefix, $ID_MEMBER;


db_query("INSERT INTO {items_purchased} (item_id, pack_id, group_id, user_id, points_spent, purchase_date)
    VALUES (329, 7, 19, '{$ID_MEMBER}', 0, " . TIME_NOW . ")");

    return 'Youve successfully equipped the Broom! Enjoy!';
}
Otsikko: Re: Fixing a code snippet
Kirjoitti: margarett - joulukuu 23, 2013, 01:08:25 IP
You should try to use $smcFunc instead. There are several examples (in SMF code itself) on how to use it to insert.

Plus, if you want to submit your MOD to our modsite we will ask you to use it :P
Otsikko: Re: Fixing a code snippet
Kirjoitti: emanuele - joulukuu 24, 2013, 08:18:00 AP
Considering what is in global Keydet is probably using SMF 1.1, so margarett he cannot use $smcFunc. ;)

The first thing I see wrong is the name of the table:

db_query("INSERT INTO {items_purchased}

I guess you wanted to write:

db_query("INSERT INTO {$db_prefix}items_purchased