Web Analytics Made Easy -
StatCounter Undefined index for a defined index. - CodingForum

Announcement

Collapse
No announcement yet.

Undefined index for a defined index.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Undefined index for a defined index.

    Arrggh. This is haunting me.
    PHP Code:
        function viewToDelete(){
            
            
    $this->connect();    
            echo 
    "<p align='left'>";
            
    $this->connect();
            
    $query "SELECT id,author,topic,email,mood,date,entry,np,month FROM blog ORDER BY id DESC";
            
    $result mysql_query($query) or die(mysql_error());
            
    $rows mysql_num_rows($result) or die(mysql_error());
            if(
    $rows == "0"){ echo "No information in database!"; }
            else {
            while(
    $row mysql_fetch_assoc($result)){
                
    $this->id $row['id'];
                
    $this->author $row['author'];
                
    $this->topic $row['topic'];
                
    $this->email $row['email'];
                
    $this->mood $row['mood'];
                
    $this->date $row['date'];
                
    $this->entry $row['entry'];
                
                echo 
    "<b><font size='3'><span id='title'>$this->topic</span><br></font><font size='2'></b>";
                echo 
    "<span id='double'>$this->entry</span>";
                echo 
    "<br><i><p align='right'></b> $this->date by <a href='mailto:$this->email'>$this->author</a> | <B>Mood:</b> $this->mood</font></i>\n";
                
    $this->commentsNumber($this->id);
                echo 
    '<br /><form action="deletepost.php" method="POST"><input type="checkbox" value="'.$this->id.'" name="bid">Delete Post?<input type="submit" value="Delete"></form>';
                echo 
    "<hr noshade color='black' size='1'></p>";
                }
            }
        }
        
        function 
    delete($id){
            
            
    $this->id $id;
            
            
    $this->connect();
            
            
    $query "DELETE FROM blog WHERE id='{$this->id}'";
            
            
    mysql_query($query) or die(mysql_error());
            
            
    $queery "DELETE FROM comments WHERE bid='{$this->id}'";
            
            
    mysql_query($queery) or die(mysql_error());
            
            
    Header("Location: ?mode=cp&cpmode=deletepost");
        } 
    I'n function viewToDelete() i output the information from a database and build a form in order to delete posts. In function delete() i use a form to delete posts. The post is being delete, but this error is given on the form action
    Notice: Undefined index: bid in c:\server\htdocs\blog\admin\deletepost.php on line 4
    deletepost.php
    PHP Code:
    <?php
    include_once('../blog.php');
    $exe = new blog;
    $exe->delete($_POST['bid']);
    ?>
    I defined the checkbox with the name "bid" in the form in function viewToDelete(). If the script is being executed, why is this error being recieved?

    Thanks
    Last edited by SDP2006; Mar 3, 2004, 05:30 PM.
    Stevie Peele
    Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
    #dev - any programming,etc. question
    #design - design discussion and critque
    #central - general chat
    Come join us!

  • #2
    Re: Undefined index for a defined index.

    <?php
    include_once('../blog.php');
    $exe = new blog;
    $exe->delete($_POST['bid']);
    ?>[/php]
    I defined the checkbox with the name "bid" in the form in function viewToDelete(). If the script is being executed, why is this error being recieved?
    This is no error, that is a notice, because you'll have E_ALL configured in your php.ini.
    If you submit the form without checking your checkbox, there is no $_POST['bid'].
    You can supress this notice using a @ like in functions.

    $exe->delete(@$_POST['bid']);

    Or check if $_POST['bid'] ist set with isset(), before.
    www.united-scripts.com
    www.codebattles.org

    Comment


    • #3
      The isset method is probably better as it will not generate an error if the value is not set, if you use the @ sign, the error is generated but not displayed or taken into account for... if you get what I mean. Its an efficiency thing, the code is more efficient if you dont have any errors generated. I only use @ on functions when my script is complete and any errors would be more related to other things such as database problems ect.
      PHP Weekly - A PHP Developers Resource
      PHP 5.1.4 and Ruby on Rails web hosting
      Moderator of PHP and Work offers and Requests
      Install Apache/PHP/MySQL
      (by marek_mar) | TinyPlugin Architecture

      Comment


      • #4
        I added that @. Thanks.
        Stevie Peele
        Neverside IRC Network - irc.veonex.net | tc.tutorialnetwork.org
        #dev - any programming,etc. question
        #design - design discussion and critque
        #central - general chat
        Come join us!

        Comment


        • #5
          Originally posted by missing-score
          The isset method is probably better as it will not generate an error if the value is not set, if you use the @ sign, the error is generated but not displayed or taken into account for...
          Yes, you're right, the isset method is more elegant, sure.
          But I insist... That is _no_error_, it is a *warning*.
          On production systems you normally turn E_ALL off, this is for developer purposes to be able to make code cleaner and for better debugging.

          I only use @ on functions...
          Well, on functions I think it's more critical than on array variables.
          But You can create your own error handling checking the return value of the functions.
          www.united-scripts.com
          www.codebattles.org

          Comment

          Working...
          X