divadiva Posted August 12, 2008 Share Posted August 12, 2008 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++; } } Quote Link to comment Share on other sites More sharing options...
trq Posted August 12, 2008 Share Posted August 12, 2008 You need to escape dangerous characters such as quotes. Ive no idea what database interface your using there but typically, using the common mysql interface people would use mysql_real_escape_string() to do the escaping. Quote Link to comment Share on other sites More sharing options...
divadiva Posted August 12, 2008 Author Share Posted August 12, 2008 Thanks worked like a charm!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.