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

Notice from sql error output

Development and Programming

Wired's avatar
Wired
181 posts
16 years ago
Wired's avatar Wired

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…

       
Brian M.'s avatar
Brian M.
529 posts
16 years ago
Brian M.'s avatar Brian M.

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 😉

       
Brian M.'s avatar
Brian M.
529 posts
16 years ago
Brian M.'s avatar Brian M.

Actually I think I might have lied. I’m not sure what line 34 is, but you probably need to do an if(isset) on $entry_id before you try to use your $results - if you have no entry_id at a tag parameter it looks like that would throw that notice.

       
Robin Sowell's avatar
Robin Sowell
13,160 posts
16 years ago
Robin Sowell's avatar Robin Sowell

You might want to put a check on

$entry_id = $TMPL->fetch_param('entry_num');

If there’s no parameter, it will error. As for the index- could you try this in the conditional instead of

if(isset($results) !== '')
    {
if ($results->num_rows > 0)
    {
       

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.