Using if statement within Editor PHP server script with $_GET
Using if statement within Editor PHP server script with $_GET
Restful Web Services
Posts: 202Questions: 49Answers: 2
I am passing 2 parameters to my Editor PHP server script which are picked up using the $_GET function. It works well however, on occasion, one of the parameters I am passing will be empty in which case I want to discard that check. I cannot understand why the following if isset check code does not work though, can anyone point me in the right direction?
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'cms_module_tps_userlisting', 'list_id' )
->fields(
Field::inst( 'listphone' ),
Field::inst( 'create_date' ),
Field::inst( 'checkcode' ),
Field::inst( 'user_id' )
)
->where( 'user_id', $_GET['user_id'] )
if ( isset($_GET['checkcode']) && !empty($_GET['checkcode']) ) {
->where( 'checkcode', $_GET['checkcode'] )
}
->process( $_POST )
->json();
Thanks
Chris
This discussion has been closed.
Answers
Hi Chris,
It looks like invalid PHP syntax to me, and you should probably be getting an error from the PHP engine. You want something like this:
Does that make sense now?
Allan
The didn't seem to do the trick but this did work.
Thanks for your help
Fair enough - although I'm curious as to why my solution didn't work. Did you get any errors from it?
However, good to hear you have a working solution!
Allan
Thanks for your help. I didn't see any errors although that didn't mean there weren't any! Thanks again.
Just to let you know, the reason your code didn't work is because it does throw a PHP error:
FastCGI sent in stderr: "PHP message: PHP Parse error: syntax error, unexpected '}'
You forgot a ; If you change to this it works
$editor->where( 'checkcode', $_GET['checkcode'] );
Doh - thanks for that. Clean missed it before! Updated the comment now incase anyone else sees it.
Allan