Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#106 2011-02-11 07:59:34

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: [archived] pap_xpoll (multiple poll plugin)

Oi Oi – I just upgraded a site to 4.3 which was using this plugin and got the following errors:

The First error is a ‘Undefined Variable’ and is something to do with safe_row

$rs = safe_row("ext, h", "txp_image", "id='$id' limit 1");

So I changed this to:

$rs = safe_row('ext, h', 'txp_image', 'id="$id" limit 1');

And it works :) – why is that?

The Second error is an ‘Undefined Index’ (poll & results) on this line

if ((!isset($_REQUEST['option']) | $_REQUEST['poll'] != $xpoll_data['poll']) && (!isset($_REQUEST['results']) | $_REQUEST['results'] != $xpoll_data['poll']) && $xpoll_data['votecookies'] != 'no' && $xpoll_data['voteip'] != 'no' && $xpoll_data['blocked'] != 'yes' && $xpoll_data['started'] == 'yes' && $xpoll_data['expired'] == 'no' && $xpoll_data['voting'] == 'yes') {

And I think its to do with $_REQUEST[‘poll’] and $_REQUEST[‘results’].

I tried to wrap it with isset (don’t laugh :)) and also found out that $_REQUEST is not a good idea – so tried this code to it use $_GET and $_POST

$_REQUEST = array_merge($_GET, $_POST);

But that didn’t work :(

So I settled on putting a @ before – @$_REQUEST[‘poll’]

Which works :) but I’d like to know why it is wrong in the first place and how to fix it if anyone has the time.

Not a biggy – but if anyone has time to explain :)

Thanks

Offline

#107 2011-02-11 10:30:06

Bloke
Developer
From: Leeds, UK
Registered: 2006-01-29
Posts: 12,422
Website GitHub

Re: [archived] pap_xpoll (multiple poll plugin)

tye wrote:

I changed this to: $rs = safe_row('ext, h', 'txp_image', 'id="$id" limit 1'); And it works :) – why is that?

Because you’ve masked the error :-) Stuff inside single quotes isn’t parsed by PHP so it’s not ‘seeing’ the $id variable any more and therefore can’t complain that it’s not set. A better method would be to revert the quotes to what they were originally and initialise the $id variable somewhere above that line. Not sure of the specifics of the plugin — you don’t want to override this value if it’s an attribute, for example — but the general approach would be:

$id = (isset($id)) ? $id : '';

(or, if desired, you could initialise the id value to something instead of using '')

The Second error is an ‘Undefined Index’ (poll & results) on this line

Same thing applies here. You need to initialise the variables. Instead of using raw $_GET and $_POST you could use TXP’s built in handler function gps() (‘Get/Post Set’)

$option = gps('option');
$poll = gps('poll');

And then wherever you see $_REQUEST['poll'], swap it out with $poll and so forth.

Hope that helps. We’ll make a programmer of you yet :-)


The smd plugin menagerie — for when you need one more gribble of power from Textpattern. Bleeding-edge code available on GitHub.

Hire Txp Builders – finely-crafted code, design and Txp

Offline

#108 2011-02-11 10:56:27

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: [archived] pap_xpoll (multiple poll plugin)

Thanks Stef – I’ll try those tomorrow

WARNING – do not hold your breath whilst trying to make me a programmer :)

Offline

Board footer

Powered by FluxBB