I did a write up on some stuff that might be helpful
here. Which, if you can follow it, should be more than enough to help you give a user an item -- and if you combine it with the item check later down the page, you should have what you need.
This would be especially good for super important quest items - does the user have a Fancy Lamp? If so, do nothing. If not, give them one.
PHP Code:
$item = "Fancy Lamp";
$hasitem = $mysidia->db->select("inventory", array("quantity"), "itemname ='{$item}' and owner='{$mysidia->user->username}'")->fetchColumn();
if($hasitem){
$document->add(new Comment("You have already obtained this {$item}!"));
} else {
$document->add(new Comment("It looks like you could use this {$item}!"));
$qty = 1;
$newitem = new StockItem($item);
$newitem->append($qty, $mysidia->user->username);
}