Link to home
Start Free TrialLog in
Avatar of Bruce Gust
Bruce GustFlag for United States of America

asked on

What does this error mean and how can I fix it?

Here's my error:

Catchable fatal error: Object of class SingleImage could not be converted to string in /mnt/vhosts/heavydutylighting.com/httpdocs/cms/mod_product/product.inc.php on line 174

Here's the SingleImage class:

	//DELETE SINGLE IMAGES TABLE, BEING LAZY, NOT DELETING IMAGE SINCE THERE SHOULDN'T BE A SPACE ISSUE ON THE SITE
		SqlQuery("","
			DELETE FROM single_images 
			WHERE uuid='".$this->featured_image."'
			OR uuid='".$this-> featured_image_index_1."'
			OR uuid='".$this-> featured_image_index_2."'
			OR uuid='".$this->diagram_thumb."'
			OR uuid='".$this->diagram_large."'
		");

Open in new window


Line 174 being WHERE uuid='".$this->featured_image."'

When I run this code in phpMyAdmin with a credible uuid value, I don't get an error, but I don't get anything that says something was deleted.

What do I need to change?
SOLUTION
Avatar of Dave Baldwin
Dave Baldwin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What is the SqlQuery() function?  We would need to see at least the class definition and the CREATE TABLE statements.
Avatar of Bruce Gust

ASKER

Ray, here's the SqlQuery() function...

function Delete(){
		//GET A LIST OF OUR SINGLE IMAGES TO ZAP

		SqlQuery("","
			DELETE
			FROM cart_products
			WHERE uuid='".$this->uuid."'
		
		");
		SqlQuery("","
			DELETE
			FROM cart_product_accesories
			WHERE uuid_1='".$this->uuid."'
		");
		SqlQuery("","
			DELETE
			FROM cart_product_basemount
			WHERE uuid_1='".$this->uuid."'
		");
		SqlQuery("","
			DELETE
			FROM parent_image_xref
			WHERE parent_image_xref.parent_uuid='".$this->uuid."'
		");
		
		SqlQuery("","
			DELETE FROM cart_product_cat_xref WHERE product_uuid='".$this->uuid."'
		");
		
		//DELETE SINGLE IMAGES TABLE, BEING LAZY, NOT DELETING IMAGE SINCE THERE SHOULDN'T BE A SPACE ISSUE ON THE SITE
		SqlQuery("","
			DELETE FROM single_images 
			WHERE uuid='".$this->featured_image."'
			OR uuid='".$this-> featured_image_index_1."'
			OR uuid='".$this-> featured_image_index_2."'
			OR uuid='".$this->diagram_thumb."'
			OR uuid='".$this->diagram_large."'
		");
	
	}

Open in new window


Dave, forgive my ignorance, but how do I display the values? I'm a procedural guy so OOP is something I'm still working through.
Maybe I am missing something, but this looks like the function name is "delete" and not "sqlquery"
?
"$this->featured_image" normally refers to a 'property' (really a kind of variable) of a class as shown on this page:  http://php.net/manual/en/language.oop5.basic.php  

Also on that page:
The pseudo-variable $this is available when a method is called from within an object context.

I do not see the class context for you using $this so I suspect your variables are emtpy.  They certainly do not refer to any properties of your function.

PS: I would use phpMyAdmin to look at the field in the database to see if there is something that can be a string there.
Dave, let me ask you something: This site was originally pulling from some raw mysql files that I converted into a phpmyAdmin dynamic. The errors that I've been having to sort through have all had the common denominator of a column within a table that was misspelled, or something like that. In other words, it hasn't been the code, however it might be improved upon. Rather, it's been something about the database. Your suggestion as far as looking at a field in the database - should I be looking for a flaw in the structure? In other words, should something be a integer rather than a varchar? Is that what you mean?
I believe you have two problems.  #1.  The code that you have shown Can't work as it it.  #2. If there is other code that actually makes what you have posted work, then your error message is saying the data found (if any) can not be converted into a string.  So use phpMyAdmin to look at the table and the columns and see what is there.  Is it something that can be a string?
Dave, here's what I found. When you insert a new product, a featured_image, a featured_image_1, a featured_image_2 - all of it is automatically entered, so there is data and it can be converted to a string in that the data is the uuid value which is something like a1E1976D7C.

So there is data, but when I try to do echo $this->featured_image; I get "Catchable fatal error: Object of class SingleImage could not be converted to string in /mnt/vhosts/heavydutylighting.com/httpdocs/cms/mod_product/product.inc.php on line 173." Line 173 is the "echo $this->featured_image

So there is data, but something about the way that data is being retrieved isn't seeing it. I've attached the System Class "SingleImage." Do you see anything suspicious there?

Here's the System Class

<?php


class SingleImage{

	var $uuid,$file_name,$size,$isnew,$imagename,$file_path,$filehaschanged;
	
	var $inputname;

	function SingleImage($inputname=""){
	
	$this->inputname=$inputname;
	
	$this->uuid=CreateId();
	$this->file_name="";
	$this->size=0;
	$this->isnew=1;
	$this->imagename="NO IMAGE SELECTED";
	$this->file_path="temp".$_SESSION['path_sep'];
	$this->filehaschanged=0;
	}


	function Load($uuid){
	
	if($uuid){
	$data= SqlQuery("","select * from single_images where uuid ='".$uuid."';");
	
	$line=mysql_fetch_array($data);
		
	$this->uuid=$line["uuid"];
	$this->file_name=$line["file_name"];
	$this->size=$line["size"];
	$this->imagename=$line["name"];
	$this->file_path="image_bank/single_images".$_SESSION['path_sep'];
	$this->isnew=0;
	}
	}

	function DeleteImage(){
		//this funtion will delete the selected pdf object from the database
		
		//delete files
		if($this->file_name != ""){
			if(file_exists(realpath($this->file_path.$this->file_name))){
				unlink(realpath($this->file_path.$this->file_name));
			}
		
		
		}
		
		// delet from database
		$sql="delete from parent_image_xref where image_uuid='".$this->uuid."';";
		SqlQuery("",$sql);
		
		SqlQuery("","delete from single_images where uuid='".$this->uuid."';");
	
	}

	function Save($parent_uuid){
	//this will save the specific item to the database
	//echo "SAVING";
		// if is new then insert into database and copy file to new location, delete old file
		if($this->isnew){
		if($this->file_name != "" and $this->imagename != "NO IMAGE SELECTED" ){

		
			//copy file to its new location in the pdf directory
			if($this->file_name != ""){
				$target_path= "image_bank/single_images";
			
				if(file_exists(realpath("temp/".$this->file_name))){
				
					//copy file to targetlocation
					$name= $this->file_name;
					
							$count=1;
						
							while(file_exists(realpath($target_path.$_SESSION['path_sep'].$name))){
								//file already exists
								$name=$count."_".strtoupper(str_replace(" ","_",str_replace("'","",$this->file_name)));
								$count++;
							}
					
					
						 copy(realpath("temp/".$this->file_name),realpath($target_path).$_SESSION['path_sep'].$name);
						
						
					unlink(realpath("temp/".$this->file_name));
					$this->file_name=$name;
				
				}
			}
			SqlQuery("","insert into single_images set uuid ='".$this->uuid."', file_name='".$this->file_name."', size='".$this->size."', name='".$this->imagename."'");
			//SqlQuery("","insert into parent_image_xref set parent_uuid='".$parent_uuid."', image_uuid='".$this->uuid."' ");
			
		}
		}else{
		// item not new so update the database with the replacement info
		
		//copy the file from temp if the file has changed
					if($this->filehaschanged){
						if($this->file_name != ""){
							$target_path= "image_bank/single_images";
						
							if(file_exists(realpath("temp/".$this->file_name))){
								
								//copy file to targetlocation
								$name= $this->file_name;
								
										$count=1;
									
										while(file_exists(realpath($target_path.$_SESSION['path_sep'].$name))){
											//file already exists
											$name=$count."_".strtoupper(str_replace(" ","_",str_replace("'","",$this->file_name)));
											$count++;
										}
								
								
									copy(realpath("temp/".$this->file_name),realpath($target_path).$_SESSION['path_sep'].$name);
									
								unlink(realpath("temp/".$this->file_name));
								$this->file_name=$name;
							
							}
						}
					
					
					}
		//update queries

			SqlQuery("","update single_images set  file_name='".$this->file_name."', size='".$this->size."', name='".$this->imagename."' where uuid ='".$this->uuid."';");
			
			//SqlQuery("","delete from parent_pdf_xref where")
			//SqlQuery("","insert into parent_pdf_xref set parent_uuid='".$parent_uuid."', pdf_uuid='".$this->uuid."' ");
		
		}
	}
	
	function DeleteFile(){
	//this function will delete the specific file assocatated with the pdf file object.
			if($this->file_name != ""){
				if(file_exists(realpath($this->file_path.$this->file_name))){
					unlink(realpath($this->file_path.$this->file_name));
					$this->file_path="";
					$this->file_name="";
					$this->imagename="";
				}
		
		
			}
		
	
	
	
	}

	function DisplayInput($formname,$control,$name="Single"){
	//this function will display the inputs for a pdf file
	echo"<script language=\"javascript\" type=\"text/javascript\">
			function validate_format".$this->inputname."(){
				if(document.".$formname.".imagefile".$this->inputname.".value !=''){
					var stringlength=document.".$formname.".imagefile".$this->inputname.".value.length;
					var extension_name=document.".$formname.".imagefile".$this->inputname.".value.substring(stringlength-3,stringlength);
					if(extension_name != 'jpg' &&  extension_name != 'gif' ){
						window.alert('Please make sure you are uploading a .jpg  or .gif file with those extensions only.');
					}else{
						document.".$formname.".control.value='".$control."';
						document.".$formname.".submit();
					}
				}else{
					window.alert('Please choose and upload an image file.');
				}
			}
		</script>";
	
		
		echo "<tr>
				<td align=\"right\" class=\"required\" valign=\"top\" style=\"padding-top:6px;\">".$name." Image (.jpg only):</td>
				<td><input name=\"imagefile".$this->inputname."\" type=\"file\" size=\"35\" >";
				DisplayButton("upload image","javascript:validate_format".$this->inputname."()");
		echo "	</td>
			</tr>";
		echo "<tr>
				<td class=\"not\" align=\"right\">Current File: </td>
				<td><input name=\"imagename".$this->inputname."\" type=\"text\" size=\"40\" value=".chr(34).$this->imagename.chr(34)."></td>
			</tr>";
		$path=$this->file_path.$this->file_name;
		
			
				
		if($this->file_name != ""){
			echo "<tr><td align=\"right\" class=\"not\">Link to Current Image: </td><td><A href=\"".$path."\" target=\"_new\" class=\"subnav\" >Click Here to View</a></td></tr>";
		}
	}

	function SaveFromOptionValue(){
	
	
	
	}
	function UpdateValues(){
	//this function will upload the file to the server temp directory
	
		if(isset($_POST["imagename".$this->inputname])){
			$this->imagename=$_POST["imagename".$this->inputname];
		
		}
		if(isset($_FILES["imagefile".$this->inputname])){
			//file value isset so deal with file upload
					$temp_dir = realpath("temp");
					//print_r($_FILES["imagefile"]);
					//upload pic to temp directory
					if(isset($_FILES["imagefile".$this->inputname])){
					
					$name=strtoupper(str_replace(" ","_",str_replace("'","",$_FILES['imagefile'.$this->inputname]['name'])));
						$count=1;
						
							while(file_exists(realpath($temp_dir.$_SESSION['path_sep'].$name))){
								//file already exists
								$name=$count."_".strtoupper(str_replace(" ","_",str_replace("'","",$_FILES['imagefile'.$this->inputname]['name'])));
								$count++;
							}
					
							$uploadtarget=$temp_dir.$_SESSION['path_sep'].$name;
				
				
				
				//file data exists
					if(move_uploaded_file($_FILES['imagefile'.$this->inputname]['tmp_name'], $uploadtarget)){
					//success
					
					$oldfilepath=$this->file_path;
					$this->file_path = "temp/";
					
					$temp = explode(".",$name);
					$this->imagename= $temp[0];
					$oldfilename= $this->file_name;
					$this->file_name= $name;
					$this->size=$_FILES['imagefile'.$this->inputname]['size']/1000;
					//echo"<br>bbk".$this->pdfname;
					
					//delete old file if it exitsed
					if($this->file_name != "" && $oldfilename != "" && $oldfilename != $this->file_name){
					//the file has changed so 
					$this->filehaschanged=1;
					//delete the old file
						if(file_exists(realpath($oldfilepath.$oldfilename)) && $oldfilename != ""){
								unlink(realpath($oldfilepath.$oldfilename));
						
						}
					
					}
					
					}else{
					echo "no upload";
					}
	
	}

		
		
		
		}


	}
}
?>

Open in new window

"echo $this->featured_image" does not appear in the code above.  It does seem that you have to call 'Load' before you call 'Delete file' because Delete does not do a database access to get any data to work with.

And so far you haven't shown me a complete row of the data.  What's in it???
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hey, Dave!

The "echo $this->featured_image" seems to be established as a result of one of three possible queries which I have documented below...

In each case, the $this->featured_image seems to established by the SingleImage class, which is why I posted it. I attempted to echo the $this->featured_image in the product.inc.php page and you see that on line 172.

<?php
class Product extends imageParent{
	var $uuid,$isnew,$name,$sku,$tech_specs,$instock,$webdisplay,$related_accesories,$related_base,$category,$description,$featured,$featured_2,$featured_image,$featured_image_index_1,$featured_image_index_2,$diagram_thumb,$diagram_large;

	function Product(){
		$this->uuid=CreateID();
		$this->isnew=1;
		$this->name="";
		$this->sku="";
		$this->tech_specs="";
		$this->instock=1;
		$this->webdisplay=1;
		$this->category="";
		$this->description="";
		$this->featured=0;
		$this->featured_2="";
		$this->related_accessories=array();
		$this->related_base=array();
		//Initilize imgage component
		$this->ItitilizeImage();
		$this->image_singles["main"]= new singleImageHolder("main");
		$this->image_defaults= array("use_cat"=>false,"show_gallery_button"=>false );
		$this->final_img_stats =  array();
		//THESE MUST BE LISTED LARGES TO SMALLEST
		$this->final_img_stats[0]="large/|345|345";
		$this->final_img_stats[1]="medium/|345|345";
		$this->final_img_stats[2]="small/|50|50";
		$this->final_img_stats[3]="thumb/|50|50";
		$this->featured_image=new SingleImage("featured_image");
		$this->featured_image_index_1=new SingleImage("featured_image_index_1");
		$this->featured_image_index_2=new SingleImage("featured_image_index_2");
		$this->diagram_thumb=new SingleImage("diagram_thumb");
		$this->diagram_large=new SingleImage("diagram_large");
	}
	function Load($uuidtoload){
		//this funtion will load a specific department from the database
			if($uuidtoload > ""){
				$SQL="SELECT * FROM cart_products WHERE uuid='".$uuidtoload."'";
				$data= SqlQuery("",$SQL);
				
				$line=mysql_fetch_array($data);
				$this->isnew=0;
				$this->uuid=$uuidtoload;
				$this->name=$line['name'];
				$this->sku=$line['sku'];
				$this->tech_specs=$line['tech_specs'];
				$this->instock=$line['instock'];
				$this->webdisplay=$line['webdisplay'];
				$this->description=$line['description'];
				$this->featured=$line['featured'];
				$this->featured_2=$line['featured_2'];
				$this->LoadImages();
				//Find related accesories
				$data_re_01=SqlQuery("","
					SELECT *
					FROM cart_product_accessories
					WHERE uuid_1='".$uuidtoload."'
				");
				$re_count=0;
				$this->related_accessories=array();
				while($line_re=mysql_fetch_array($data_re_01)){
					if($line_re['uuid_1']==$uuidtoload){
						$this->related_accessories[$re_count] = $line_re['uuid_2'];
					}else{
						$this->related_accessories[$re_count] = $line_re['uuid_1'];
					}
					$re_count++;
				}
				//Find related basemounts
				$data_re_01=SqlQuery("","
					SELECT *
					FROM cart_product_basemount
					WHERE uuid_1='".$uuidtoload."'
				");
				$this->related_base=array();
				while($line_re=mysql_fetch_array($data_re_01)){
					if($line_re['uuid_1']==$uuidtoload){
						$this->related_base[$re_count] = $line_re['uuid_2'];
					}else{
						$this->related_base[$re_count] = $line_re['uuid_1'];
					}
					$re_count++;
				}
				$this->featured_image->Load($line['featured_image']);
				$this->featured_image_index_1->Load($line["featured_image_index_1"]);
				$this->featured_image_index_2->Load($line["featured_image_index_2"]);
				$this->diagram_thumb->Load($line["diagram_thumb"]);
				$this->diagram_large->Load($line["diagram_large"]);
				//GET CATEGORIES
				$data2=SqlQuery("","SELECT cart_product_cat.catname,cart_product_cat.uuid as cat_uuid,cart_product_subcat.subname,cart_product_cat_xref.subcat_uuid 
						FROM cart_product_cat_xref
						LEFT JOIN cart_product_cat ON cart_product_cat_xref.cat_uuid = cart_product_cat.uuid
						LEFT JOIN cart_product_subcat ON cart_product_cat_xref.subcat_uuid = cart_product_subcat.uuid
						WHERE cart_product_cat_xref.product_uuid  ='".$this->uuid."'
						ORDER BY cart_product_cat.catname,cart_product_subcat.subname
					");

				if(mysql_num_rows($data2) > 0){
					while($line=mysql_fetch_array($data2)){
						if($line["subcat_uuid"] == ""){
							$value=$line["cat_uuid"];
						}else{
							$value=$line["subcat_uuid"];
						}
						$this->cat_array[$value]=new Category();
						$this->cat_array[$value]->Load($value);
					}

				}
			}else{
				$this->uuid=CreateID();
				$this->isnew=1;
				$this->name="";
				$this->sku="";
				$this->tech_specs="";
				$this->instock=1;
				$this->webdisplay=1;
				$this->related_accessories=array();
				$this->related_base=array();
				$this->description="";
				$this->featured=0;
				$this->featured_2=0;
				$this->featured_image=new SingleImage("featured_image");
				$this->featured_image_index_1=new SingleImage("featured_image_index_1");
				$this->featured_image_index_2=new SingleImage("featured_image_index_2");
				$this->diagram_thumb=new SingleImage("diagram_thumb");
				$this->diagram_large=new SingleImage("diagram_large");
			}
		
	}
	function GetName(){
		return $this->name;
	}	
	function CanSave(){
		return true;
	}
	function GetUUID(){
		return $this->uuid;
	}
	

	function Delete(){
		//GET A LIST OF OUR SINGLE IMAGES TO ZAP

		SqlQuery("","
			DELETE
			FROM cart_products
			WHERE uuid='".$this->uuid."'
		
		");
		SqlQuery("","
			DELETE
			FROM cart_product_accesories
			WHERE uuid_1='".$this->uuid."'
		");
		SqlQuery("","
			DELETE
			FROM cart_product_basemount
			WHERE uuid_1='".$this->uuid."'
		");
		SqlQuery("","
			DELETE
			FROM parent_image_xref
			WHERE parent_image_xref.parent_uuid='".$this->uuid."'
		");
		
		SqlQuery("","
			DELETE FROM cart_product_cat_xref WHERE product_uuid='".$this->uuid."'
		");
		 
		//DELETE SINGLE IMAGES TABLE, BEING LAZY, NOT DELETING IMAGE SINCE THERE SHOULDN'T BE A SPACE ISSUE ON THE SITE
		echo $this->featured_image;
		SqlQuery("","
			DELETE FROM single_images 
			WHERE uuid='".$this->featured_image."'
			OR uuid='".$this-> featured_image_index_1."'
			OR uuid='".$this-> featured_image_index_2."'
			OR uuid='".$this->diagram_thumb."'
			OR uuid='".$this->diagram_large."'
		");
	
	}
	

Open in new window


So I attempt to "see" $this->featured_image on 172 believing that it should be present based on either line 29 or line 84 or line 123.

Is there a way I can figure out which of those three scenarios is actually being deployed? And then from there determine where the gap is occurring?

Thanks for your time!
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for the input, guys! I've determined to introduce another query that will provide the variables that I'm missing. It's a bandaid, but a healthy one nevertheless. Hopefully the client will be open to a more updated design in the near future and this will all be a moot point.