Fork me on GitHub

Delete Function  Bottom

  • alright, i'm trying to develop a module, and when i try to delete an item, the delete function returns a "NO ITEM FOUND" error/ this is the code from the delete functions is amin.php and adminapi.php

    PNADMIN:

    Code

    function gpPortfolio_admin_delete($args)
    {
        list($pid,
             $objectid,
             $confirmation) = pnVarCleanFromInput('pid',
                                                  'objectid',
                                                  'confirmation');


        extract($args);

        if (!empty($objectid)) {
            $pid = $objectid;
        }

        if (!pnModAPILoad('gpPortfolio', 'user')) {
            return pnVarPrepHTMLDisplay(_LOADFAILED);
        }

        $item = pnModAPIFunc('gpPortfolio',
                             'user',
                             'get',
                             array('pid' => $pid));

        if (!$item) {
            return pnVarPrepHTMLDisplay(_PORTFOLIONOSUCHITEM);
        }

        if (!pnSecAuthAction(0, 'gpPortfolio::', "$item[title]::$pid", ACCESS_DELETE)) {
            return pnVarPrepHTMLDisplay(_MODULENOAUTH);
        }

        if (empty($confirmation)) {

            $pnRender =& new pnRender('gpPortfolio');

            $pnRender->caching = false;

            $pnRender->assign('pid', $pid);

            return $pnRender->fetch('gp_portfolio_admin_delete.htm');
        }

        if (!pnSecConfirmAuthKey()) {
            pnSessionSetVar('errormsg', pnVarPrepHTMLDisplay(_BADAUTHKEY));
            pnRedirect(pnModURL('gpPortfolio', 'admin', 'view'));
            return true;
        }

        if (!pnModAPILoad('gpPortfolio', 'admin')) {
            pnSessionSetVar('errormsg', pnVarPrepHTMLDisplay(_LOADFAILED));
            pnRedirect(pnModURL('gpPortfolio', 'admin', 'view'));
            return true;
        }

        if (pnModAPIFunc('gpPortfolio',
                         'admin',
                         'delete',
                         array('pid' => $pid))) {
            pnSessionSetVar('statusmsg', pnVarPrepHTMLDisplay(_PORTFOLIODELETED));
        }

        pnRedirect(pnModURL('gpPortfolio', 'admin', 'view'));

        return true;
    }
  • We need to see the API function that does the actual SQL stuff too.

    --
    Home Page | Find on Facebook | Follow on Twitter
  • ok

    Code

    function gpPortfolio_adminapi_delete($args)
    {
        extract($args);

        if ((!isset($pid)) ||
            (isset($pid) && !is_numeric($pid))) {
            pnSessionSetVar('errormsg', _MODARGSERROR);
            return false;
        }

        if (!pnModAPILoad('gpPortfolio', 'user')) {
            pnSessionSetVar('errormsg', _LOADFAILED);
            return false;
        }

        $item = pnModAPIFunc('gpPortfolio',
                             'user',
                             'get',
                              array('pid' => $pid));

        if (!$item) {
            pnSessionSetVar('errormsg', _PORTFOLIONOSUCHITEM);
            return false;
        }

        if (!pnSecAuthAction(0, 'gpPortfolio::', "$item[name]::$pid", ACCESS_DELETE)) {
            pnSessionSetVar('errormsg', _MODULENOAUTH);
            return false;
        }

        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();

        $pftable  = &$pntable['gp_portfolio'];
        $pfcolumn = &$pntable['gp_portfolio_column'];

        $sql = "DELETE FROM $pftable
                WHERE $pfcolumn[pid] = '"
    . (int)pnVarPrepForStore($pid) ."'";
        $dbconn->Execute($sql);

        if ($dbconn->ErrorNo() != 0) {
            pnSessionSetVar('errormsg', _DELETEFAILED);
            return false;
        }

        pnModCallHooks('item', 'delete', $pid, '');

        $pnRender =& new pnRender('gpPortfolio');
        $pnRender->clear_cache(null, $pid);

        return true;
    }
  • I'd start by putting

    [code]
    print $SQL; break;
    right after you define $SQL and before you actually do the execute. That will show you what the query is that's being passed to MysQL and you can run it in phpMyAdmin and see what the error is hopefully.

    --
    Home Page | Find on Facebook | Follow on Twitter
  • i got it! thanks

This list is based on users active over the last 60 minutes.