For some reason I get this: Notice: Undefined index: entry_id in /htdocs/admincp/plugins/pi.poll.php on line 34
And here’s my code:
class Poll
{
var $return_data ;
function Poll()
{
global $DB,$TMPL;
$poll_title = 'Is this person naughty or not?';
$entry_id = $TMPL->fetch_param('entry_num');
$results = $DB->query("SELECT * FROM poller WHERE entry_id = '$entry_id'");
if(isset($results) !== '')
{
if( $results->row['entry_id'] !== $entry_id)
{
$data = array(
'ID' => '',
'pollerTitle' => $poll_title,
'entry_id' => $entry_id,
);
$sql = $DB->insert_string('poller',$data);
$DB->query($sql);
echo $last_entry = $DB->insert_id;
}
else
{
echo 'This entry is already in the system so run this code';
}
}
else
{
echo '2nd section of the script';
}
}
}
The script works because the data is inserted into the db but it annoys me that I’m getting a notice of some sort. It might screw something up in the long run so…
Not sure if you fixed this already (month old post) - but you can just declare $entry_id earlier and it will keep that from happening. So just put
$entry_id = '';
somewhere before your notice is being thrown. I tend to get a lot of these as well, because I’ll have errors off while writing something and then turn it on to track down a problem and notice I’ve got a ton. If you declare all the vars you’re going to be using down the road in advance you won’t get this, but that’s hard to remember to do sometimes 😉
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.