0

What's wrong with this code? I'm getting a blank page for this?

<?php 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'); $db = JFactory::getDbo(); $user = JFactory::getUser(); $profile = JUserHelper::getProfile($user->id); if( $user->username == 'THE_USER_1' ) { $query = $db->getQuery(true); $query->select($db->quoteName('username')); ->from($db->quoteName('#table_name#')); ->where($db->quoteName('username') . ' = '. $db->quote($user->username)); $db->setQuery($query); $result = $db->loadResult(); if($result) { echo "<p> You have already filled the form.</p>"; } else { // continue to form page } elseif( $user->username == 'THE_USER_2' ) { // some code } else { echo "<p> Sorry, you can't access this page.</p>"; } ?> 
2
  • A blank page generally means that there are PHP errors. I would highly recommend displaying errors while writing new code. The system will highlight exact lines where you are missing things like brackets and semicolons. Commented May 28, 2014 at 16:13
  • @DavidFritsch .. the code is almost fixed! check the answer below. Commented May 28, 2014 at 17:00

1 Answer 1

1

Firstly, you are missing a closing brackets in your if statement. Also, you are carrying on the database query having ended the previous line with a semi-colon. I don't know what you have also done when defining the database table, but you should replace #table_name# with #__table_name.

Copy and paste the code below which includes the missing closing bracket, removal of additional semi-colons and correct table name:

<?php 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'); $db = JFactory::getDbo(); $user = JFactory::getUser(); $profile = JUserHelper::getProfile($user->id); if( $user->username == 'THE_USER_1' ) { $query = $db->getQuery(true); $query->select($db->quoteName('username')) ->from($db->quoteName('#__table_name')) ->where($db->quoteName('username') . ' = '. $db->quote($user->username)); $db->setQuery($query); $result = $db->loadResult(); if($result) { echo "<p> You have already filled the form.</p>"; } } elseif( $user->username == 'THE_USER_2' ) { // some code } elseif( $user->username !== 'THE_USER_1' || $user->username !== 'THE_USER_2' ) { echo "<p> Sorry, you can't access this page.</p>"; } else { echo "display form"; } ?> 

Hope this helps

15
  • still getting a blank page? Commented May 27, 2014 at 16:15
  • even when i access the page as "THE_USER_2" , i still get a blank page? Commented May 27, 2014 at 16:25
  • I will need to do some tests when I get back from work. Will report back soon Commented May 27, 2014 at 16:52
  • No issues Lodder! & btw thankyou, in advance. i know you'll find a solution to this problem. ;) Commented May 27, 2014 at 17:26
  • Ahh, you had an elseif after an else statement which isn't allowed. I've edited my code accordingly. Please try again Commented May 27, 2014 at 17:48

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.