i use JInput to get data from a form and insert that into the database, but it only works when the PHP file containing the JInput script is placed inside the root folder?


define( '_JEXEC', 1 );
define('JPATH_BASE', __DIR__);
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
$app = JFactory::getApplication('site');
$user = JFactory::getUser();
$profile = JUserHelper::getProfile($user->id);

$input = JFactory::getApplication()->input;
$username = $input->get('username');
$choice = $input->get('choice');

$db = JFactory::getDbo(); 
$query = $db->getQuery(true);

$columns = array('username', 'choice');
$values = array($db->quote($username), $db->quote($choice));

  ->values(implode(',', $values));


header("Location: /choice");


I also tried to define the JPATH_BASE outside root folder with this :

('JPATH_BASE','../../'); which always used to work while importing Joomla CMS outside root directory, but with this JInput stuff, i am getting a blank page?


2 Answers 2


If you get a blank page, it usually means that the server encountered a fatal error. You should either turn on error reporting and set it to a development level or check the server error log. There should be something written there.

If you move this script outside the root, you sure need to adjust the file paths in your require_once statements. It needs the path from your current file to the Joomla folder and its libraries.

  • the paths to both the require_once's are correct! and i use php pages with imported joomla cms and they work fine outside root folder?
    – saibbyweb
    Jun 10, 2014 at 19:24
  • What does the error log say?
    – Bakual
    Jun 10, 2014 at 20:49
  • @Saibbyweb - Can you add var_dump($app); somewhere in your code and see if anything gets exported. It should dump a load of data on the page, however if it doesn't, then Bakual is right and the path's you have set are incorrect
    – Lodder
    Jun 10, 2014 at 21:39

You cannot set JPATH_BASE as relative, rather use the approach of the files in the /cli folder:

if (file_exists(dirname(dirname(__FILE__)) . '/defines.php'))
    require_once dirname(dirname(__FILE__)) . '/defines.php';

if (!defined('_JDEFINES'))
    define('JPATH_BASE', dirname(dirname(__FILE__)));
    require_once JPATH_BASE . '/includes/defines.php';

and, the library you're missing is probably defines itself! Additionally you can output some code to ensure you're actually including the library based on having _JDEFINES defined or not.

Not the answer you're looking for? Browse other questions tagged or ask your own question.