How to check the query string?

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
taylort

How to check the query string?

Post 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!
Duketown

Re: How to check the query string?

Post 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
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to check the query string?

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
taylort

Re: How to check the query string?

Post 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?
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: How to check the query string?

Post by calguy1000 »

You can't mix smarty and php variables in that way.

try:  {if isset($smarty.request.status) && $smarty.request.status eq 'success')}
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
taylort

Re: How to check the query string?

Post 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.
Pierre M.

Re: How to check the query string?

Post by Pierre M. »

Hello,

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

Pierre M.
Post Reply

Return to “Developers Discussion”