Page 1 of 1

How to check the query string?

Posted: Fri Dec 28, 2007 12:32 am
by taylort
I would like to check the query string within a page to see if the status variable has been passed and, if so, what it's value is.

Here's the full path: http://domain.com/page/?status=success

I would to know that "status" has indeed been passed and was a success. If it's just

http://domain.com/page

Then I know that there's not a status passed. There must be an incredibly easy way to do this; I'm simply not familiar with PHP. Can anyone help?

Thanks!

Re: How to check the query string?

Posted: Fri Dec 28, 2007 7:32 am
by Duketown
taylort,

You can use the echo function in PHP. Just after you updated a table you could have the following:

Code: Select all

echo "DEBUG: result = ".$db->ErrorMsg()."<br/>  ".$db->sql."<br/>"; die();
This will display what the actual query was against the database. Take special care of the last part: die() as  this stops your application immediatly.
Showing if a parameter has been passed. CMSMS normaly uses the $params to pass the parameters. This is an array of values. A nifty option is to use:

Code: Select all

debug_display($params);
This will show the values of the array in a nice readable way.
Simple way could also be:

Code: Select all

echo ('Status parameter contains: '.$params['status']);
Duketown

Re: How to check the query string?

Posted: Fri Dec 28, 2007 7:23 pm
by calguy1000
taylort wrote: I would like to check the query string within a page to see if the status variable has been passed and, if so, what it's value is.

Here's the full path: http://domain.com/page/?status=success

I would to know that "status" has indeed been passed and was a success. If it's just

http://domain.com/page

Then I know that there's not a status passed. There must be an incredibly easy way to do this; I'm simply not familiar with PHP. Can anyone help?

Thanks!
This is basic PHP stuff..... if the variable was passed by GET, the variable will be in $_GET.  if the variable was passed by POST the value will be in $_POST.  If you don't care which method the variable was passed by check $_REQUEST.

Re: How to check the query string?

Posted: Sat Dec 29, 2007 3:00 am
by taylort
This seems outrageously simple but I'm having more trouble than anything. Here's the very simple code that I've added to the top of one of my pages:

Code: Select all

{if $_REQUEST['status'] eq 'success'}
  Thank you for submitting your information!
{else}
  Please submit your information.
{/if}
No matter what I pass in the query string it will display the "Please submit your information." I know it's likely something simple I need to change.

Any suggestions?

Re: How to check the query string?

Posted: Sat Dec 29, 2007 4:46 pm
by calguy1000
You can't mix smarty and php variables in that way.

try:  {if isset($smarty.request.status) && $smarty.request.status eq 'success')}

Re: How to check the query string?

Posted: Wed Jan 02, 2008 7:15 pm
by taylort
calguy1000 wrote: You can't mix smarty and php variables in that way.

try:  {if isset($smarty.request.status) && $smarty.request.status eq 'success')}

You are the man! That fixed it - thanks so much for the help everyone.

Re: How to check the query string?

Posted: Wed Jan 02, 2008 7:31 pm
by Pierre M.
Hello,

feel free to add it in the wiki. You can contribute with your forum account.
Happy new year

Pierre M.