We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

My PHP is broke

Development and Programming

Sam Sullivan's avatar
Sam Sullivan
64 posts
13 years ago
Sam Sullivan's avatar Sam Sullivan

Hi,

I get an error message “Invalid GET Data - Array”.

My php scripts works fine in a regular mypage.php file, but not when using an EE template.

I tried parsing in and out without any luck.

This type of php is OK in template:

echo $_GET["id"];

Seems to be problem when GET does an array using square brackets:

echo $_GET["id"][0];
echo $_GET["id"][1];
echo $_GET["id"][2];
       
mark186282's avatar
mark186282
290 posts
13 years ago
mark186282's avatar mark186282

Depending on your server config, you may get differing results.

First, try and see what PHP knows of the _GET variable:

<pre>
<?PHP
print_r($_GET);
?>
</pre>

<p>
</pre>

it will make it very clear how PHP is treating the GET variables… based on the results of the code above, we can figure out what is going on.

What is an example of the query string you are trying to retrieve data from?

….

You may also want to explore (if you haven’t already) the input class of EE:

http://ellislab.com/expressionengine/user-guide/development/usage/input.html#this-ee-input-get

       
Sam Sullivan's avatar
Sam Sullivan
64 posts
13 years ago
Sam Sullivan's avatar Sam Sullivan

Hi Mark,

I tried your code, this is result:

Array
(
)

I’ve never needed to use EE classes before, what can they do for me?

       
Sam Sullivan's avatar
Sam Sullivan
64 posts
13 years ago
Sam Sullivan's avatar Sam Sullivan

Here’s my URL with parameters:

http://www.mysite.com/?id[]=blue&id;[]=yellow&id;[]=red&id;[]=green&submit=GO

Here’s the PHP to get parameters:

<?php
echo $_GET["id"][0]."
";
echo $_GET["id"][1]."
";
echo $_GET["id"][2]."
";
echo $_GET["id"][3]."
";
?>

Result:

blue
yellow
red
green
       
mark186282's avatar
mark186282
290 posts
13 years ago
mark186282's avatar mark186282

regarding classes:

many many benefits for using the built in functions and classes of the system… and ideally, you would encapsulate them in a plugin, extension or module - but for simple stuff on a page to do some little tricks… it’s up to you. The official stance is to limit the use of PHP in the template as much as possible - For the record, I’m the biggest offender of breaking that rule.

one of the biggest advantages is Security. If you are using an input class, you have an added layer of protection against SQL injections and other attempts to hack your environment.

(there are other reasons that others may chime in on as well)

…

Back to your code….

Did you run my snippet on the same page as your code? (if so, something is awry… because it should have spit out your get variables)

http://www.mysite.com/?id[]=blue&id;[]=yellow&id;[]=red&id;[]=green&submit=GO

and on that page:

<?php
echo $_GET["id"][0]."
";
echo $_GET["id"][1]."
";
echo $_GET["id"][2]."
";
echo $_GET["id"][3]."
";

print "<pre>";
print_r($_GET);
print "</pre>

<p>”;</p>

<p>?>
</pre> (what is the output of the above?

………..

How you would use the input class in this example would be something like:

<?PHP

$this->EE =& get_instance();

$input_id = $this->EE->input->get('id');

print "<pre>";
print_r($input_id);
print "</pre>

<p>”;</p>

<p>?>
</pre>

       
Sam Sullivan's avatar
Sam Sullivan
64 posts
13 years ago
Sam Sullivan's avatar Sam Sullivan

Hey Mark,

Thanks for switching on the EE class light bulb!

I’ve been putting off looking at plugins etc - now been pushed to the top of my to-do list.

I’ll have a play with this, and thanks for making it sound so clear.

… regarding the test, I can’t get past the error message, must be the square brackets in the URL.

thanks,

Sam

       
mark186282's avatar
mark186282
290 posts
13 years ago
mark186282's avatar mark186282

sure thing.

are the semicolons in your URL intentional?

       
Sam Sullivan's avatar
Sam Sullivan
64 posts
13 years ago
Sam Sullivan's avatar Sam Sullivan

no there shouldn’t be any semicolons, my bad editing, they weren’t in the original url.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.