Forums

Update database query not working?

huubs 21 Mar, 2017
Hello,

I'm trying to update a row in my articles database, with a custom code.

$db =& JFactory::getDBO();
$query = "
SELECT *
FROM `#__content`
WHERE `id`='203'";
$db->setQuery($query);
$data = $db->loadAssocList();

$countArticles = count($data);

if($countArticles > 1){
    $articlesIDarray;

    for($i=0; $i < $countArticles; $i++){
        $articlesIDarray.push($data[$i]['id']);
    }

    $latestIDnumber = max($articlesIDarray);
} else {
    $latestIDnumber= $latestArticle['id'];
}


//Catid update

$query2 = "
UPDATE `jos_content` SET `catid` = '".$form->data['category']."' WHERE `id`='203'";
$db->setQuery($query2);

echo $query2;


This gives as line of code:

UPDATE `jos_content` SET `catid` = '14' WHERE `id`='203'


Which is a legit MySQL string, it works in PHYMyadmin, but not via this way. Does someone know if Chronoforms needs another parameter to update or something?
GreyHead 21 Mar, 2017
Hi huubs,

Please try adding
$db->execute($query2);
to actually execute the query?
Bob
huubs 21 Mar, 2017
Yeah, that's it. Thanks.
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount
hostinger