Jump to content

[SOLVED] How to ignore comma in sql query returned with results in PHP


divadiva

Recommended Posts

When ever I run my code I get this error :

Database Error while executign query: insert into data(WebsiteId, Serial, Manufacturer, Price, Site, onmarket) values('95830', '', 'Long's Mfg.', '', 'CATALYST', 1) You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's Mfg.', '', 'CATALYST', 1)' at line 1.

The error is that there is an estra comma in Long'sMfg.How to ignore this comma.

 

The way the data is inserted in database via my code is

$query .=  "('".trim($cols->item(1)->nodeValue)."', '', '".$cols->item(2)->nodeValue."',  '".$cols->item($colcount-2)->nodeValue."', 'CATALYST'";

 

 

I have attached the code that inserts the data.any help will be appreciated:

if(strlen($cols->item(2)->nodeValue))	//if has at least manufacturer
	{
		if(checkExists('CATALYST', $cols->item(1)->nodeValue) == 0)
		{
			//build insert query
			$query =  "insert into data(WebsiteId, Serial, Manufacturer,  Price, Site";

			if($descriptionfound)
				$query .= ", Description";
			else
			{
				if($sizefound)
					$query .= ", Wafersize";
				if($processfound)
					$query .= ", Process";
			}

			$query .= ", onmarket) values";

			$query .=  "('".trim($cols->item(1)->nodeValue)."', '', '".$cols->item(2)->nodeValue."',  '".$cols->item($colcount-2)->nodeValue."', 'CATALYST'";

			if($descriptionfound)
				$query .= ", '".$cols->item(4)->nodeValue."'";
			else
			{	
				if($sizefound)
					$query .= ", '".$cols->item(4)->nodeValue."'";
				if($processfound)
					$query .= ", '".$cols->item(5)->nodeValue."'";
			}	
			$query .= ", 1)";

			executeNonQuery($query);	//execute the insert query
		}
	}
	$i++;
   }	
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.