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++;
   }	
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.