Current location: Hot Scripts Forums » Programming Languages » PHP » PHP delete from MySQL Error (PHP ERROR)


PHP delete from MySQL Error (PHP ERROR)

Reply
  #1 (permalink)  
Old 01-31-07, 12:29 AM
_matt _matt is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow PHP delete from MySQL Error (PHP ERROR)

I get this error
PHP Code:

Fatal errorCall to a member function on a non-object in /home/httpd/vhosts/xyz.com/httpdocs/casa/catalogclass.php on line 109 

here is the code Im using. (I am new to this please be easy)
PHP Code:

<?

    
require_once "databaseclass.php";


    class 
catalogclass extends databaseclass{
        
        var 
$thumbnail;
        var 
$mainpic;
        var 
$description;    
        var 
$directory;
        var 
$directory1;
        var 
$pagesize;
        var 
$pageindex=0;
        var 
$rows;
        var 
$rowcount;
        var 
$i=0;
        var 
$row;
        var 
$condition;
        var 
$category;
        var 
$command;
    
 
        function 
setThumbnail($value){
        
            
$this->thumbnail=$value;
        
        }

        function 
setMainPic($value){
        
            
$this->mainpic=$value;
        
        }

        function 
setDescription($value){
        
            
$this->description=$value;
        
        }

        function 
setDirectory($value){
        
            
$this->directory=$value;
        }
        function 
setDirectory1($value){
        
            
$this->directory1=$value;
        }

        
        function 
setPageSize($value){
        
            
$this->pagesize=$value;
        
        }
        

        function 
setPageIndex($value){
        
            
$this->pageindex=$value-1;
        
        }
        function 
getSearch(){
            
            return 
$this->queryME("select * from Catalog WHERE title LIKE '%$search%' || description LIKE '%search%' || category LIKE '%$search%'");            
            
        }

        function 
getCategories(){
            
            return 
$this->queryME("SELECT category from Catalog group by category");            
            
        }
        
        function 
setCategory($value){

            
$this->category=$value;

        }


        function 
display(){    

            
$this->indexSize();        
            
$this->i=0;
            
            
            if(
$this->category=="All"){
                
$this->command="SELECT Mainpic,Description,Category,Height,Width,Depth,Location,Title,Price,Main2,Main3,Main4,Itemid from Catalog order by rand() limit 4" ;
            }else{
                
$this->command="SELECT Mainpic,Description,Category,Height,Width,Depth,Location,Title,Price,Main2,Main3,Main4,Itemid from Catalog WHERE category = '".$this->category."' limit ".$this->pageindex*$this->pagesize.",".$this->pagesize;
            }
            
$this->rows=$this->queryME($this->command);
            
$horizontal=0;
            print 
"<table  width=\"576\" aling=\"center\">";
            while(
$this->row mysql_fetch_assoc($this->rows)){
                if(
$horizontal%4==0)
                    print 
"<tr valign=top>";
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<td valign="top"><table border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td valign="top"><div align="center"><a href="display.php?mainpic=<? print $this->directory1."/".$this->row[Mainpic];?>&title=<? print $title str_replace(" ","%20",$this->row[Title]);?>&price=<? print $this->row[Price];?>&height=<? print $this->row[Height];?>&width=<? print $this->row[Width];?>&depth=<? print $this->row[Depth];?>&location=<? print $location str_replace(" ","%20"$this->row[Location]);?>&description=<? print $description str_replace(" ","%20"$this->row[Description]);?>&main2=<? print $this->row[Main2];?>&main3=<? print $this->row[Main3];?>&main4=<? print $this->row[Main4];?>"><img src="<? print $this->directory."/".$this->row[Mainpic];?>" width="125" height="125" border="5" style="border-color:#B3B0B0" /></a></div></td>
    </tr>
    <tr>
      <td><div align="center" class="titlec"><? print $this->row[Title];?>/<? print $this->row[Itemid];?></div></td>
    </tr>
    <tr>
      <td><? if($_POST['delete']){
$row=$databaseobject->queryMe("DELETE FROM Catalog where itemid ='$itemid'");
};
?>
        <form action="<?php echo $PHP_SELF?>" method="post" name="delete">
          <input type="hidden" name="itemid" value="<? print $this->row[Itemid];?>" />
          <input name="delete" type="submit" value="delete" />
        </form></td>
    </tr>
  </table></td>
<? if($horizontal%4==3){
                    print 
"</tr>";
                }

                
$this->i++;
                if(
$this->i>=$this->pagesize){
                    break;
                }
                
$horizontal++;
            }
            print 
"</table>";
            
$this->indexSize();

            
        }

        function 
indexSize(){


            if(
$this->category!="All" && $this->category!=""){
                
$this->rows=$this->queryME("SELECT count(*) as size from Catalog where category='".$this->category."'");
            }else{
                
$this->rows=$this->queryME("SELECT count(*) as size from Catalog");
            }


            
$this->rowcount=mysql_fetch_assoc($this->rows);
            if(
$this->rowcount[size]%$tihs->pagesize>&& $this->rowcount[size]>$this->pagesize){
                
$this->condition=($this->rowcount[size]/$this->pagesize) + 1;
            } else{    
                
$this->condition=$this->rowcount[size]/$this->pagesize;    
            }

            
            
            



        }
}

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 01-31-07, 12:45 AM
grafman grafman is offline
Coding Addict
 
Join Date: Dec 2006
Posts: 278
Thanks: 0
Thanked 0 Times in 0 Posts
_matt,

A class object didn't get created somewhere. Its not the class that you are using its an argument to a class method that is of datatype "object" that this class needs.

The error is your class complaining that it didn't get something that it needed. look at the code that "calls" the object instance of the class and look for a parameter or argument that is a class object. In most cases its probably one or two lines above where this method is called.

You get experienced by solving lots of these sorts of problems.

Keep plugging away!
__________________
"Things are difficult only while you don't understand them."
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 01-31-07, 04:58 AM
Vicious's Avatar
Vicious Vicious is offline
Community VIP
 
Join Date: Jan 2007
Location: Belgium
Posts: 584
Thanks: 0
Thanked 0 Times in 0 Posts
there's something wrong with line 109:
PHP Code:

$databaseobject->queryMe("DELETE FROM Catalog where itemid ='$itemid'"
A non-object means that $databaseobject is not an instance of the database class you're using. So either you need to make an instance of that class in $databaseobject:
PHP Code:

$databaseobject = new DatabaseObject(); 

(or something similar)

Or there's an error in your database class.
__________________
Jack Bauer makes Chuck Norris cry
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 01-31-07, 01:06 PM
_matt _matt is offline
Newbie Coder
 
Join Date: Oct 2006
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Ok so I think I have the command to work, but now I get this error.
catalogclass.php
PHP Code:

<?

    
require_once "databaseclass.php";

    class 
catalogclass extends databaseclass{
        
        var 
$thumbnail;
        var 
$mainpic;
        var 
$description;    
        var 
$directory;
        var 
$directory1;
        var 
$pagesize;
        var 
$pageindex=0;
        var 
$rows;
        var 
$rowcount;
        var 
$i=0;
        var 
$row;
        var 
$condition;
        var 
$category;
        var 
$command;
        var 
$delete;
    
 
        function 
setThumbnail($value){
        
            
$this->thumbnail=$value;
        
        }

        function 
setMainPic($value){
        
            
$this->mainpic=$value;
        
        }

        function 
setDescription($value){
        
            
$this->description=$value;
        
        }

        function 
setDirectory($value){
        
            
$this->directory=$value;
        }
        function 
setDirectory1($value){
        
            
$this->directory1=$value;
        }

        
        function 
setPageSize($value){
        
            
$this->pagesize=$value;
        
        }
        

        function 
setPageIndex($value){
        
            
$this->pageindex=$value-1;
        
        }
        function 
getDelete(){
            
            return 
$this->queryME("DELETE FROM Catalog where itemid ='$itemid'");            
            
        }

        function 
getCategories(){
            
            return 
$this->queryME("SELECT category from Catalog group by category");            
            
        }
        
        function 
setCategory($value){

            
$this->category=$value;

        }


        function 
display(){    

            
$this->indexSize();        
            
$this->i=0;
            
            
            if(
$this->category=="All"){
                
$this->command="SELECT Mainpic,Description,Category,Height,Width,Depth,Location,Title,Price,Main2,Main3,Main4,Itemid from Catalog order by rand() limit 4" ;
            }else{
                
$this->command="SELECT Mainpic,Description,Category,Height,Width,Depth,Location,Title,Price,Main2,Main3,Main4,Itemid from Catalog WHERE category = '".$this->category."' limit ".$this->pageindex*$this->pagesize.",".$this->pagesize;
            }
            
$this->rows=$this->queryME($this->command);
            
$horizontal=0;
            print 
"<table  width=\"576\" aling=\"center\">";
            while(
$this->row mysql_fetch_assoc($this->rows)){
                if(
$horizontal%4==0)
                    print 
"<tr valign=top>";
?>
<link href="style.css" rel="stylesheet" type="text/css" />
<td valign="top"><table border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
      <td valign="top"><div align="center"><a href="display.php?mainpic=<? print $this->directory1."/".$this->row[Mainpic];?>&title=<? print $title str_replace(" ","%20",$this->row[Title]);?>&price=<? print $this->row[Price];?>&height=<? print $this->row[Height];?>&width=<? print $this->row[Width];?>&depth=<? print $this->row[Depth];?>&location=<? print $location str_replace(" ","%20"$this->row[Location]);?>&description=<? print $description str_replace(" ","%20"$this->row[Description]);?>&main2=<? print $this->row[Main2];?>&main3=<? print $this->row[Main3];?>&main4=<? print $this->row[Main4];?>"><img src="<? print $this->directory."/".$this->row[Mainpic];?>" width="125" height="125" border="5" style="border-color:#B3B0B0" /></a></div></td>
    </tr>
    <tr>
      <td><div align="center" class="titlec"><? print $this->row[Title];?>/<? print $this->row[Itemid];?></div></td>
    </tr>
    <tr>
      <td><? if($_POST['delete']){
      
      
$this->rows=$this->queryME($this->delete);
      while(
$this->row mysql_fetch_assoc($this->rows));

};
?>
        <form action="<?php echo $PHP_SELF?>" method="post" name="delete">
          <input type="hidden" name="itemid" value="<? print $this->row[Itemid];?>" />
          <input name="delete" type="submit" value="delete" />
        </form></td>
    </tr>
  </table></td>
<? if($horizontal%4==3){
                    print 
"</tr>";
                }

                
$this->i++;
                if(
$this->i>=$this->pagesize){
                    break;
                }
                
$horizontal++;
            }
            print 
"</table>";
            
$this->indexSize();

            
        }

        function 
indexSize(){


            if(
$this->category!="All" && $this->category!=""){
                
$this->rows=$this->queryME("SELECT count(*) as size from Catalog where category='".$this->category."'");
            }else{
                
$this->rows=$this->queryME("SELECT count(*) as size from Catalog");
            }


            
$this->rowcount=mysql_fetch_assoc($this->rows);
            if(
$this->rowcount[size]%$tihs->pagesize>&& $this->rowcount[size]>$this->pagesize){
                
$this->condition=($this->rowcount[size]/$this->pagesize) + 1;
            } else{    
                
$this->condition=$this->rowcount[size]/$this->pagesize;    
            }

            
            
            



        }
}

?>
error when I hit the delete button
PHP Code:

Could not match data because Query was empty 

I dont know why it would be empty, the form get the ItemId and the function asked for the '$itemid'.

What am I missing beside school ;-)
[php]

Last edited by _matt; 01-31-07 at 01:11 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
IIS MYSQL and PHP nommiiss PHP 6 01-31-06 05:30 PM
WEB HOSTING - $4.99/MONTH For 1GB HD & 25GB BW! CPanel, PHP, MySQL & MORE! IncognitoNet General Advertisements 0 12-10-05 09:13 AM
single quote "'" error in mysql query by php sjems PHP 4 09-27-05 09:36 AM
Delete files/directories selected in MySQL ronlar PHP 3 08-08-05 09:41 AM
PHP multi-dimensional array sorting issue aqw PHP 2 06-25-05 12:09 AM


All times are GMT -5. The time now is 04:42 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.