mercredi 4 octobre 2017

This code works by itself, but won't execute as an if(isset ..) statement

I have a small bit of code that seems to work as expected when I test it stand alone ( I set a variable for $fcode of course) but when I wrap it in an if(isset..) statement the db query does not seem to execute.

if (isset($_POST["query_details"]))
{
    $fcode = $_POST['code'];

    $session = JFactory::getSession();
    $external_db = array();
    $external_db['driver'] = 'mysqli';
    $external_db['host'] = 'localhost';
    $external_db['user'] = 'findlayfoods';
    $external_db['password'] = 'Beb0pdab0p';
    $external_db['database'] = 'findlay_products';

    $db = &JDatabase::getInstance($external_db);
    $query = $db->getQuery(true);
    $query->select('sku, description, pgroup, pack, brk, vendor_num, portions, prtn_sz');
    $query->from($db->quoteName('findlay_inv'));
    $query->where($db->quotename('sku') . '= ' . $db->quote($fcode));
    $db->setQuery($query);

    $row = $db->loadRow();

    $code_description = $row[1];
    $code_group = $row[2];
    $code_pack = $row[3];
    $code_vendor = $row[5];
    $code_portion = $row[6];
    $code_size = $row[7];
    $fcode_check = date('H:i:s');

}

When I execute this code, without the if statement, it queries my database and runs.

When I wrap the code in the if(isset ..) statement, I get $fcode being set with the proper value from $_POST['code'] but I don't get any data pulled from mysqli and displayed by the print_r command and $fcode_check does not get set.

Since $fcode gets set, the code is entering the if statement. I just do not see why I can not query the db and set the $fcode_check variable.

I am a bit stumped, any suggestions would be appreciated.

G

Aucun commentaire:

Enregistrer un commentaire