Custom code does not work anymore

Resolve a blank page and failed redirect in custom CF code.

Overview

The issue is caused by deprecated PHP syntax and an undefined variable in Joomla 3.
Update the code by removing the deprecated reference operator and properly initializing the Joomla application object for the redirect function.

Answered
th thyl123 01 Nov, 2015
Hey Guys,

this custom code doesn't work anymore.


<?php
$db =& JFactory::getDBO();
$query = "
    SELECT COUNT(*)
        FROM `xxxxx_chronoengine_chronoforms_Spargelturnier_2016`
        WHERE `selector` = '1' ;
";
$db->setQuery($query);
$count = $db->loadResult();
if ( $count > 1 ) {
  $mainframe->redirect(JURI::root().'index.php/wir-sind-voll.html'); 
}
?>


There is only a blank white page shown. No redirection to index.php/wir-sind-voll.html. The-Redirection-Page is public.

Thank you for your ideas.
Gr GreyHead 02 Nov, 2015
Answer
1 Likes
Hi thy123,

Please see this FAQ

In Joomla! 3 you should remove the & from the second line.

Also $mainframe isn't defined in your code snippet, you might need to add
$app = JFactory::getApplication(); // add this line
$app->redirect(JURI::root().'index.php/wir-sind-voll.html'); // update this one

Bob
This topic is locked and no more replies can be posted.