More validation fun with PHP

arcadeicons

Member
I'm trying to run this PHP script during onLoad of my form to check if the person accessing the form has the rights to actually use it to submit a score.

Code:
$jinput = JFactory::getApplication()->input;
$tournID = JRequest::getVar('tournID');
$user = JFactory::getUser();
$myDb = JFactory::getDbo();
$myQuery = $myDb->getQuery(true);
$myQuery
   ->select('*')
   ->from('add_tournament_199_repeat')
   ->where('parent_id') . ' = ' . $tournID
   ->where('add_remove_score_keepers') . ' = ' . {$user->id};

var_dump((string) $myQuery);
$myDb->setQuery($myQuery);
$result = $myDb->loadObjectList();

if ($result = "0") {
    print ("Hey you are not a judge for this tournament");
} else {
    print ("Looks like you are a judge");
}

exit;

Neither the var_dump or the print statements show any output on the page so I don't know if the script is performing the check properly, what am I missing here?
 
Last edited:
I think I mentioned on another thread that you need an...

exit;

... after var_dump() during a submit, as the output from the submit never gets seen, as there's a redirect.

Sent from my HTC6545LVW using Tapatalk
 
The syntax helped and enabled me to see the results of var_dump, I guess it was crashing before it even got there before. If the check returns no result I want to kill the form before it even renders which exit achieves nicely (this is a secondary security measure to stop anyone manually manipulating the URL to try and post scores when they aren't a nominated Judge).

How do I write the if statement to say if there are no results in the array then exit? I've tried ="NULL", ="", < 0 with not much luck

Code:
$jinput = JFactory::getApplication()->input;
$tournID = JRequest::getVar('tournID');
$user = JFactory::getUser();
$myDb = JFactory::getDbo();

$myQuery = $myDb->getQuery(true);
$myQuery
   ->select('id')
   ->from('add_tournament_199_repeat')
   ->where('parent_id = ' . $tournID)
   ->where('add_remove_score_keepers = ' . $user->id);  

$myDb->setQuery($myQuery);
$results = $myDb->loadObjectList();

if ($result = '') {
    exit;
};
 
Thanks, but unfortunately that doesn't initiate the exit when there are no matches

Code:
$jinput = JFactory::getApplication()->input;
$tournID = JRequest::getVar('tournID');
$user = JFactory::getUser();
$myDb = JFactory::getDbo();

$myQuery = $myDb->getQuery(true);
$myQuery
   ->select('id')
   ->from('add_tournament_199_repeat')
   ->where('parent_id = ' . $tournID)
   ->where('add_remove_score_keepers = ' . $user->id);  

$myDb->setQuery($myQuery);
$results = $myDb->loadObjectList();

if ($results =='') {
    exit;
};
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top