Solved

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

Posted on 2013-01-15
13
312 Views
Last Modified: 2013-01-18
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?
0
Comment
Question by:brucegust
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 82

Assisted Solution

by:Dave Baldwin
Dave Baldwin earned 225 total points
Comment Utility
First, see what type those items are declared as.  Then you need to display those values and see what they are.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
What is the SqlQuery() function?  We would need to see at least the class definition and the CREATE TABLE statements.
0
 

Author Comment

by:brucegust
Comment Utility
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.
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Maybe I am missing something, but this looks like the function name is "delete" and not "sqlquery"
?
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
"$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.
0
 

Author Comment

by:brucegust
Comment Utility
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?
0
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
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?
0
 

Author Comment

by:brucegust
Comment Utility
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

0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
"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???
0
 
LVL 108

Assisted Solution

by:Ray Paseur
Ray Paseur earned 225 total points
Comment Utility
When this fails: echo $this->featured_image it means that you need to provide the __toString() method.  You might want to use var_dump() to print out the object.

This question dialog is all very confused.  We have error messages with line numbers, but we've never seen the actual code with line numbers that match the error message!  And we don't have the underlying data model, or even the CREATE TABLE statement.  It's not likely that we can offer much help except to point to the "scary things" we see in the code (and there are a lot of those).  Here is what I recommend.  Read about the SSCCE here: http://sscce.org and reduce the problem to a succinct demonstration of the error(s).  Post that reduced code set, along with the data definitions and enough of the data that we can recreate the data base and produce the error on our machines.  Then we will be able to get "hands-on" into the debugging process, and you'll have a solution very quickly.

Now to the "scary stuff."  This code looks like a relic of the old (horrid) PHP4 days.  It is going to choke to death on its own crud, perhaps as soon as the next release of PHP5, and therefore it must be refactored.  If you're clear about how to write PHP OO programming and you have the time to do that sort of work, you could tackle the project yourself.  If not, you might want to hire a professional programmer to get to work on it.  Or you might consider scrapping the entire thing and rebuilding it on top of a modern CMS like Drupal.  There is no quick-fix for some of this stuff -- it's just too old and the underlying technologies are changing.
0
 

Author Comment

by:brucegust
Comment Utility
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!
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 50 total points
Comment Utility
greetings brucegust, there's a whole lot of code to go through for this debug, so my suggestion is largely a "GUESS" of the code I did look at,  as you can see this -
$this->featured_image
is an OBJECT in the "class Product" code so you can not get any useful string data from it unless you tell it the property or function to reference, as far as I can tell you need to use the uuid property as -
$this->featured_image->uuid
maybe as (can NOT check the "  and '  here )
WHERE uuid='".$this->featured_image->uuid."'

but you may need to get a better grasp on what these classes (singleImage  and Product) do and their relationship to each othe, especially since  singleImage  is a Sub-Object of Product.

I hope this helps ?
0
 

Author Closing Comment

by:brucegust
Comment Utility
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.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now